时钟案例
2018-01-16 本文已影响0人
複製粘貼
function changeTime() {
//获取事件,创建日期对象
var date = new Date();
console.log(date);
//获取时分秒
// var ms =date.getMilliseconds();
var sec = date.getSeconds(); //+ ms / 1000;
var min = date.getMinutes();
console.log (sec, min);
var hr = date.getHours()+ min/60;
console.log(hr);
//动画
second.style.transform = 'rotate(' + 6 * sec +'deg)';
minute.style.transform ='rotate(' + 6 * min +'deg)';
hour.style.transform = 'rotate(' + 30 * hr +'deg)';
}
changeTime();
var time = setInterval(changeTime,1000);
console.log(time);