表盘

今天主要学习了日期对象,然后简单做了一个钟表的小demo

+

new date() :创建日期

getDate(); 获得日期(月份中的某一天)

getDay(); 获得星期几

getFullYear(); 获得年份

getMonth(); 获得月份 0~11 0表示1月 11表示12月

getHours(); 获得小时

getMinutes(); 获得本地分钟

getSeconds(); 获得本地秒

getTime(); 获得毫秒: 1970年1月1号 0晨至今的毫秒数

demo

1
2

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
<body>
<div class="box">
<div class="circle">
<span class="a"></span>
<span class="b"></span>
<span class="c"></span>
<div class="fz">
<div>12</div>
<div>9</div>
<div>3</div>
<div>6</div>
</div>
<div class="fz-1">
<div>1</div>
<div>4</div>
<div>7</div>
<div>10</div>
</div>
<div class="fz-2">
<div>2</div>
<div>5</div>
<div>8</div>
<div>11</div>
</div>
</div>
</div>
</body>

css

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<style type="">
*{
margin:0;
padding:0;
}
.box{
width:400px;
height:400px;
border-radius:10px;
background:black;
margin:30px auto;
}
.circle{
width:300px;
height:300px;
border-radius:50%;
border:1px pink solid;
background:snow;
margin:0px auto;
position:relative;
top:50px;
}
.a{
width:5px;
height:75px;
position:absolute;
top:75px;
left:150px;
background:black;
transform-origin:2.5px 65px;
}
.b{
width:3px;
height:100px;
position:absolute;
top:50px;
left:151px;
background:gray;
transform-origin:1.5px 90px;
}
.c{
width:2px;
height:130px;
position:absolute;
top:20px;
left:151.5px;
background:red;
transform-origin:1px 120px;
}
.fz,.fz-1,.fz-2{
width:210px;
height:210px;
font-size:20px;
}
.fz{
position:absolute;
top:45px;
left:45px;
transform:rotateZ(45deg);
}
.fz-1{
position:absolute;
top:45px;
left:45px;
transform:rotateZ(75deg);
}
.fz-2{
position:absolute;
top:45px;
left:45px;
transform:rotateZ(105deg);
}
.fz>div,.fz-1 >div,.fz-2 >div{
width:16px;
position:absolute;
}
.fz div:nth-child(1){
left:0;
top:0;
transform:rotateZ(-45deg);
}
.fz div:nth-child(2){
width:16px;
position:absolute;
left:0;
bottom:0;
transform:rotateZ(-45deg);
}
.fz div:nth-child(3){
width:16px;
position:absolute;
right:0;
top:0;
transform:rotateZ(-45deg);
}
.fz div:nth-child(4){
width:16px;
position:absolute;
right:0;
bottom:0;
transform:rotateZ(-45deg);
}
.fz-1 div:nth-child(1){
left:0;
top:0;
transform:rotateZ(-75deg);
}
.fz-1 div:nth-child(2){
right:0;
top:0;
transform:rotateZ(-75deg);
}
.fz-1 div:nth-child(3){
right:0;
bottom:0;
transform:rotateZ(-75deg);
}
.fz-1 div:nth-child(4){
left:0;
bottom:0;
transform:rotateZ(-75deg);
}
.fz-2 div:nth-child(1){
left:0;
top:0;
transform:rotateZ(-105deg);
}
.fz-2 div:nth-child(2){
right:0;
top:0;
transform:rotateZ(-105deg);
}
.fz-2 div:nth-child(3){
right:0;
bottom:0;
transform:rotateZ(-105deg);
}
.fz-2 div:nth-child(4){
left:0;
bottom:0;
transform:rotateZ(-105deg);
}
</style>

js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script type="">
var timer=null;
timer =setInterval(function(){
var riQi = new Date();
var hours =riQi.getHours();
var minutes =riQi.getMinutes();
var seconds =riQi.getSeconds();
var hou =document.querySelector(".a");
var minu =document.querySelector(".b");
var seco =document.querySelector(".c");
seco.style.transform = "rotateZ("+(seconds*6)+"deg)";
minu.style.transform = "rotateZ("+(minutes*6 +seconds*0.1)+"deg)";
hou.style.transform = "rotateZ("+(hours*30+minutes*0.5+seconds/120)+"deg)";
},1000);
</script>