Hello readers, Today in this blog you’ll learn how to create realtime pendulum clock with Javascript. Earlier, you have learned to send email using php. I have also created a blog on other cool stuffs of web designing.

 

Creating such pendulum clock is really fun and full of excitement. Trying these sorts of fun projects help you to grow your skills. Today I’m going to show you how you can create a realtime pendulum clock with awesome animation. The whole animation is done with CSS and the time showing functionality is created in Javascript. At first, I have created some div for the frame, pendulum & other parts of clock then I have styled them nicely with CSS and at last, I have created time showing functionality using Javascript.

 

As you notice, the numbers of the clock are perfectly placed at correct position just like in real clock. For that I have given the ‘position relative’ property to the parent div and ‘position absolute’ property to the child div which makes all numbers from 1 to 12 to be placed at the same place by overlapping each other. After that, I have rotated the numbers starting from 30 degree to 360 degree increasing each by the value of 30.

 

The pendulum complete its animation within 2 seconds but it is given for infinite time so the animation never ends. Pendulum moves 30 degree to the right and return to 0 degree within 1 second and then it moves 30 degree to the left and again return to 0 degree within remaining 1 second. I have also set the ‘transform-origin’ property at the top of the pendulum which does not allow to move the top of pendulum. It makes the top of pendulum to be placed at same position without rotating. That’s all how I animate pendulum. The cross at the bottom of the pendulum is created with the ‘after’ pseudo element which has the clip-path property to give the cross shape.

 

For getting exact time I have used the ‘Date()’ function of Javascript, then I have stored the hour, minute & second value in different variables. I have submitted the hour time to hour hand, minute time to minute hand & second time to second hand. At last I have set the rotation property to all the hands so that they continue their rotation as per time. That’s all I have done for showing time with hands.


If you’re feeling difficult to understand what I am saying. You can watch a full video tutorial on this program (Real Time Pendulum Clock with Javascript).

 

You Might Also Like

Video Tutorial of Real Time Pendulum Clock with Javascript

All this page design and animation is based on CSS and time showing is based on Javascript. If you’re a beginner you can also create this type pendulum clock. If you like this program (Real Time Pendulum Clock with Javascript) and want to get source code. You can easily get the source code of this program. To get the source code you just need to scroll down.

Real Time Pendulum Clock with Javascript [Source Codes]

To create this program (Real Time Pendulum Clock with Javascript), you need to create three files one HTML file, one CSS file & one Javascript file. After creating these files just paste the following code in your file. First, create an HTML file with the name of index.html and paste the given codes in your HTML file. Note it, you’ve to create a file with .html extension.

HTML

Second, create a CSS file with the name of style.css and paste the given code in your CSS file. Note it, you’ve to create a file with .css extension.

CSS

At last, create a Javascript file with the name of script.js and paste the given code in your Javascript file. Note it, you’ve to create a file with .js extension.

 JavaScript

That’s all, now you’ve successfully created a Real Time Pendulum Clock with Javascript. If your code does not work or you’ve faced any errors/problems then please comment down. If you feel this article had helped you, please share it with your friends.

Post a Comment

أحدث أقدم