-
Notifications
You must be signed in to change notification settings - Fork 0
/
20161204时钟.html
104 lines (96 loc) · 2.48 KB
/
20161204时钟.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
ul{
list-style: none;
}
#clock{
height: 200px;
width: 200px;
border: 1px solid black;
border-radius:50%;
margin: 100px auto;
position: relative;
}
#dial li{
height: 4px;
width: 2px;
background-color: black;
position: absolute;
left: 99px;
top: 0;
-webkit-transform-origin: center 100px;
}
#dial li:nth-child(5n+1){
height: 8px;
}
#hour{
height: 35px;
width: 6px;
background-color: blue;
position: absolute;
left: 97px;
top: 65px;
-webkit-transform-origin: center bottom;
}
#minute{
height: 45px;
width: 4px;
background-color: black;
position:absolute;
left: 98px;
top: 55px;
-webkit-transform-origin: center bottom;
}
#second{
height: 55px;
width: 2px;
background-color: lightblue;
position: absolute;
left: 99px;
top: 45px;
-webkit-transform-origin: center bottom;
}
</style>
</head>
<body>
<div id="clock">
<ul id="dial">
<li></li>
<li></li>
</ul>
<div id="minute" ></div>
<div id="hour"></div>
<div id="second"></div>
</div>
<script>
var oDial =document.getElementById('dial');
var oHour = document.getElementById('hour');
var oMinute = document.getElementById('minute');
var oSecond = document.getElementById('second');
var html = '';
for(var i=0;i>60;i++){
html += "<li style='-webkit-transform: rotate("+ i * 6 +"deg)'></li>";
}
oDial.innerHTML = html;
function run(){
var date = new Date();
var second = date.getSeconds(),
minute = date.getMinutes() + second/60,
hour = date.getHours() + minute/60;
oHour.style.WebkitTransform = 'rotate('+ hour * 30 +'deg)';
oMinute.style.WebkitTransform = 'rotate('+ minute * 6 +'deg)';
oSecond.style.WebkitTransform = 'rotate('+ second * 6 +'deg)';
}
run();
setInterval(run,1000);
</script>
</body>
</html>