As I work on designing a clock, I have implemented a combination of JS and CSS to create a seamless animation for the clock's "hands." This involves converting seconds, minutes, and hours into their corresponding degrees in the analog clock:
function clock() {
var t = moment(),
s = t.seconds() * 6,
a = t.minutes() * 6,
o = t.hours() % 12 / 12 * 360 + (a / 12);
$(".hour").css("transform", "rotate(" + o + "deg)");
$(".minute").css("transform", "rotate(" + a + "deg)");
$(".second").css("transform", "rotate(" + s + "deg)");
}
setInterval(clock, 1000);
One issue I encountered is that after reaching 360 degrees, I don't want the variable to continue increasing indefinitely. Instead, I prefer it to return to 0 and start over. However, CSS causes the hands to rotate anticlockwise, creating an unwanted effect.
I've contemplated removing the transition property using JS when transitioning from 360 back to 0, and then reapplying it. While this could be a solution, I'm curious if there might be a cleaner approach.