Git Product home page Git Product logo

analog_clock.github.io's Introduction

  • Hour hand, minute hand , second hand are created by css and it's movement are added with the help of javascript.

Prerequisite

  • HTML-5
  • CSS
  • Javascript

Let's begins

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Analog Clock</title> 
    <link rel="stylesheet" href="index.css"> //link css file
    <script src="index.js"></script>  // link js file
</head>
<body>
    <div class="clockContainer">
        <div id="hour"></div>
        <div id="minute"></div>
        <div id="second"></div>
    </div>


</body>
</html>

CSS Code

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.clockContainer{
    height:600px;
    width:600px;
    display: flex;
    justify-content: center;
    align-items: center;
    background:url(alarm_clock.png);
    background-repeat: no-repeat;
    background-position: center;
    /*background-attachment: fixed;*/
    
}  


#hour,#minute,#second{
    position: absolute;;
    border-radius:10px;
    transform-origin: bottom;
}
#hour {
    width:10px;
    height:105px;
    margin-top:-32px;
    margin-left:5px;
    background:black;
}
#minute{
    width:5.5px;
    height:140px;
    margin-top:-73px;
    margin-left:5px;
    background:blue;
}
#second{
    width:2px;
    height:170px;
    margin-top:-112px;
    margin-left:5px;
    background:red;
}
.clockContainer:after{
    content: '';
    border-radius:50%;
    width: 17px;
    height:17px;
    margin-top:56px;
    margin-left:4px;
    background:red;
    position: absolute;
}

Javascript Code

setInterval(() => {
    date=new Date();
    hrtime=date.getHours();//get hr ;
    mntime=date.getMinutes();//get minutes;
    sctime=date.getSeconds();//get seconds;
    hrrot=30*hrtime + mntime/2;
    mnrot=6*mntime;
    scrot=6*sctime;
    hour.style.transform=`rotate(${hrrot}deg)`;
    minute.style.transform=`rotate(${mnrot}deg)`;
    second.style.transform=`rotate(${scrot}deg)`;

}, 1000); 

analog_clock.github.io's People

Contributors

kr123manish avatar

Stargazers

Sujal jadhav avatar Siddharth Singh Chouhan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.