I am facing a small issue with my CSS3/jQuery analog clock.
Currently, the movement of the clock hands is a bit abrupt. I would like the animation to be smooth. I attempted using transition: all .1s
, but it gets messy when the clock hands reach the top position.
The hands of the clock are being rotated using transform: rotate()
. Each movement rotates them by 6 degrees.
A potential solution could involve changing the rotation angles to make the animation smoother. Instead of rotating each hand by 6 degrees every second, minute, or hour, consider rotating by 1 degree for every 1/6th of a second for the second-hand, every 10 seconds for the minute-hand, and every 10 minutes for the hour-hand. This adjustment might create a more seamless animation effect, although the implementation details are not clear to me.
This is the JavaScript code snippet:
$(function() {
setInterval( function() {
var seconds = new Date().getSeconds();
var sdegree = seconds * 6;
var srotate = "rotate(" + sdegree + "deg)";
$("#sec").css({ "transform": srotate });
}, 1000 );
setInterval( function() {
var hours = new Date().getHours();
var mins = new Date().getMinutes();
var hdegree = hours * 30 + (mins / 2);
var hrotate = "rotate(" + hdegree + "deg)";
$("#hour").css({ "transform": hrotate});
}, 1000 );
setInterval( function() {
var mins = new Date().getMinutes();
var mdegree = mins * 6;
var mrotate = "rotate(" + mdegree + "deg)";
$("#min").css({"transform" : mrotate });
}, 1000 );
});
Check out the jsFiddle Demo here
If you understand the problem and have any insights, I would greatly appreciate your help :)