Home  >  Article  >  Web Front-end  >  How to use js to get the local time as a local pointer

How to use js to get the local time as a local pointer

一个新手
一个新手Original
2017-09-23 09:50:211866browse

Make a mechanical clock, clock background, and create an animation effect of three-hand deflection

1. Get the local time

Get the three-hand Object (no details about the style)

var h = document.getElementById("h");
var m = document.getElementById("m");
var s = document.getElementById("s");

Get local time

function setTime(){
var date = new Date();

1)

//思路:设置秒针旋转角度;60 = 360deg; 1 = 6deg;
var seceonds = date.getSeconds();//获取当前秒数
s.style.transform=" rotate("+6*senconds+"deg)";
//(style中的样式transform =rotate(x deg))旋转多少度;
// 60分钟 = 360deg 1分钟=6deg;
var minutes = date.getMinutes();
m.style.transform = "rotate(" + 6 * minutes + "deg)";
//设置时针
//12小时 = 360deg 1小时=30deg
var hours = date.getHours();
h.style.transform = "rotate(" + 30 * hours + "deg)";
}
setTime();函数调用执行
setInterval(setTime,1000);


The above is the detailed content of How to use js to get the local time as a local pointer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn