Digital clock using JavaScript, CSS, HTML

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript clock</title>
    <link rel="stylesheet" href="st.css">
</head>

<body>
    <div class="clock">
        <div class="hour">
            <div class="hr" id="hr"></div>
        </div>
        <div class="min">
            <div class="mn" id="mn"></div>
        </div>
        <div class="sec">
            <div class="sc" id="sc"></div>
        </div>
    </div>
    <script type="text/javascript">
        const deg = 6;
        const hr = document.querySelector('#hr');
        const mn = document.querySelector('#mn');
        const sc = document.querySelector('#sc');

        setInterval(() => {
            let day = new Date();
            let hh = day.getHours() * 30;
            let mm = day.getMinutes() * deg;
            let ss = day.getSeconds() * deg;

            hr.style.transform = `rotateZ(${(hh) + (mm / 12)}deg)`;
            mn.style.transform = `rotateZ(${mm}deg)`;
            sc.style.transform = `rotateZ(${ss}deg)`;
        })
    </script>

</body>

</html>



CSS FILE

* {
    margin0;
    padding0;
    box-sizingborder-box;
}

body {
    displayflex;
    justify-contentcenter;
    align-itemscenter;
    min-height100vh;
    background#091921;
}

.clock {
    width350px;
    height350px;
    displayflex;
    justify-contentcenter;
    align-itemscenter;
    backgroundurl(clock.png);
    background-sizecover;
    border4px solid #091921;
    border-radius50%;
    box-shadow0 -15px 15px rgba(2552552550.05);
}

.clock:before {
    content'';
    positionabsolute;
    width15px;
    height15px;
    backgroundrgb(191717);
    border-radius50%;
    z-index10000;
}

.clock .hour,
.clock .min,
.clock .sec {
    positionabsolute;
}

.clock .hour,
.hr {
    width160px;
    height160px;
}

.clock .min,
.mn {
    width190px;
    height190px;
}

.clock .sec,
.sc {
    width230px;
    height230px;
}

.hr,
.mn,
.sc {
    displayflex;
    justify-contentcenter;
    /* align-items: center;*/
    positionabsolute;
    border-radius50%;
}

.hr:before {
    content'';
    positionabsolute;
    width8px;
    height80px;
    background#073c5a;
    z-index10;
    border-radius6px 6px 0 0;
}

.mn:before {
    content'';
    positionabsolute;
    width4px;
    height90px;
    background#111110;
    z-index11;
    border-radius6px 6px 0 0;
}

.sc:before {
    content'';
    positionabsolute;
    width2px;
    height150px;
    background#8350e0;
    z-index12;
    border-radius6px 6px 0 0;
}



Clock Image:






Comments

Popular Posts