I'm quite new to JavaScript and I have trouble working with etInterval()
.
I'm creating an analogue clock as an exercise. I have a function setTime()
that gets and displays the time by rotating the arrows accordingly.
I want to execute this function again and again.
Here is my code :
$(document).ready(function(){
function setTime(){
var d = new Date();
var hour = d.getHours();
var minute = d.getMinutes();
var hourRotation = hour * 30 + (minute / 2);
var minuteRotation = minute * 6;
$("#small").css({
"-webkit-transform": "rotate(" + hourRotation + "deg)",
"-moz-transform": "rotate(" + hourRotation + "deg)",
"-o-transform": "rotate(" + hourRotation + "deg)"
});
$("#big").css({
"-webkit-transform": "rotate(" + minuteRotation + "deg)",
"-moz-transform": "rotate(" + minuteRotation + "deg)",
"-o-transform": "rotate(" + minuteRotation + "deg)"
});
};
function clockStart(){
setInterval(setTime(),1000);
setTime();
}
clockStart();
});
I'd like to understand this method and how to use it. The examples I could find looked so obvious, but still I can't make it work.