Home > Web Front-end > JS Tutorial > body text

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

一个新手
Release: 2017-09-23 09:50:21
Original
1865 people have browsed it

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");
Copy after login

Get local time

function setTime(){
var date = new Date();
Copy after login

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);
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!