Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Automobiles (12)
    • Cars (7)
  • Blog (103)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (51)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

CSSJQuery

Create an Analog Clock using HTML, CSS and jQuery

By Admin
February 11, 2021 2 Min Read
0

In this article, we are going to learn to create/develop a working analog clock using HTML, CSS and jQuery.

The basic login in this analog clock lies in the fact that a complete one round is equivalent to 360 degrees. The position of hour hand, minute hand and second hand are determined accordingly.

Full Source Code :

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>	
<style type="text/css">
  body{
    background: #ddd;
  }

  section {
      width: 80vmin;
      height: 80vmin;
      margin: auto;
      background: #fff;
      border: 3vmin solid #000;
      border-radius: 50%;
      margin-top: 3vmin;
      box-shadow: 
          inset 40px 40px 90px rgba(0,0,0,.2),
          inset 10px 10px 30px rgba(0,0,0,.5), 
          20px 20px 30px rgba(0,0,0,.4),
          40px 40px 60px rgba(0,0,0,.4);
      position: relative;
      z-index: 1;
  }

  section:before {
      content: '';
      width: 95%;
      height: 95%;
      border-radius: 50%;
      display: block;
      background: transparent;
      border: 2vmin solid white;
  }

  section:after {
      content: '';
      width: 105%;
      height: 105%;
      border-radius: 50%;
      display: block;
      background: transparent;
      position: absolute;
      top: -2.5%;
      left: -2.5%;
      box-shadow: -3px -3px 9px rgba(255,255,255,.8);
  }

  .label {
      position: absolute;
      top: 19vmin;
      left: 46%;
      font-size: 2.5vmin;
  }

  .hourhand,
  .secondhand,
  .minutehand {
      width: 25vmin;
      height: 2vmin;
      background: #000;
      position: absolute;
      top: 40vmin;
      left: calc(50% - 3.5vmin);
      z-index: 2;
      transform: rotate(-139deg);
      transform-origin: 16%;
      display: none;
  }

  .hourhand:after,
  .secondhand:after,
  .minutehand:after {
      content: '';
      background: #000;
      width: 5vmin;
      height: 5vmin;
      border-radius: 50%;
      z-index: 3;
      position: absolute;
      top: -1.5vmin;
      left: 1.5vmin;
  }

  .hourhand {
      border-top-right-radius: 20%;
      border-bottom-right-radius: 20%;
      box-shadow: -10px 0px 10px rgba(0,0,0,.4);
  }

  .minutehand {
      width: 40vmin;
      height: 1vmin;
      top: 40.5vmin;
      transform: rotate(-39deg);
      transform-origin: 10%;
      border-top-right-radius: 30%;
      border-bottom-right-radius: 30%;
      box-shadow: -10px 10px 10px rgba(0,0,0,.4);
  }

  .minutehand:before {
        content: '';
        width: 4.5vmin;
        height: 4.5vmin;
        border-radius: 50%;
        z-index: 99;
        position: absolute;
        top: -1.7vmin;
        left: 1.7vmin;
        box-shadow: -2px -2px 7px rgba(255,255,255,.6);
    }

  .minutehand:after {
      top: -2vmin;
  }

  .secondhand {
      width: 35vmin;
      height: .5vmin;
      top: 40.75vmin;
      transform: rotate(160deg);
      transform-origin: 11.5%;
      box-shadow: -10px -10px 10px rgba(0,0,0,.4);
  }
  .secondhand:after {
      top: -2.25vmin;
  }

  .hour12,
  .hour1,
  .hour2,
  .hour3,
  .hour4,
  .hour5 {
      height: 1vmin;
      width: 55vmin;
      background: transparent;
      border-left: 7vmin solid #000;
      border-right: 7vmin solid #000;
      transform: translate(-50%, -50%);
      top: 50%;
      left: 50%;
      position: absolute;
  }

  .hour3 { transform: rotate(90deg) translate(0, 34vmin); }

  .hour1 { transform: rotate(120deg) translate(17vmin, 30vmin); }

  .hour2 { transform: rotate(150deg) translate(29vmin, 18vmin); }

  .hour4 { transform: rotate(210deg) translate(30vmin, -17vmin); }

  .hour5 { transform: rotate(240deg) translate(17vmin, -30vmin); }
</style>

<section>
    <div class="label">ROLEX</div>
    <div class="hourhand"></div>
    <div class="secondhand"></div>
    <div class="minutehand"></div>
    <div class="hour12"></div>
    <div class="hour1"></div>
    <div class="hour2"></div>
    <div class="hour3"></div>
    <div class="hour4"></div>
    <div class="hour5"></div>
</section>	

<script type="text/javascript">
  setInterval(function(){
    setTime();
  },1000);

  setTimeout(function(){
    $(".minutehand").slideDown();
    $(".secondhand").slideDown();
    $(".hourhand").slideDown();
  },1100);

  function setTime(){
    var d = new Date();
    var seconds = d.getSeconds();
    var minutes = d.getMinutes();
    var hours = d.getHours();

    hour_degree = minutes/60*30;

    second_degree = 270 + (seconds*6);
    $(".secondhand").css('transform','rotate('+second_degree+'deg)');

    minute_degree = 270 + (minutes*6);
    $(".minutehand").css('transform','rotate('+minute_degree+'deg)');

    $(".hourhand").css('transform','rotate('+hour_degree+'deg)');
  }
</script>

 

Follow this video for complete guidance :

Design Reference : https://codepen.io/nilsynils/pen/EZzyVB

 

Tags:

analog clockclock
Author

Admin

Follow Me
Other Articles
Previous

Simple HTML parser using PHP

Next

Create Custom Music Player using HTML, CSS and JavaScript

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide
  • Chiranjibi Adhikari Appointed Acting President of CAN Federation
  • How to Design a Student Marksheet Using HTML and CSS

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You Admin
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide Admin
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme