-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.html
90 lines (83 loc) · 2.63 KB
/
Demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
</head>
<body>
<canvas id="myCanvas" height="500px" width="500px" style="margin:0 auto;display:block"></canvas>
<script>
var can = document.getElementById('myCanvas').getContext('2d');
var temp = 5;
draw();
function draw() {
can.clearRect(0, 0, 500, 500);
var oDate = new Date();
document.title = oDate.getHours() + ',' + oDate.getMinutes() + ',' + oDate.getSeconds();
//表盘
can.beginPath();
can.arc(250, 250, 100, 0, 360, false);
can.closePath();
can.strokeStyle = '#f60';
can.stroke();
for (var i = 0; i < 60; i++) {
temp--;
// alert(temp);
if (temp == 0) {
temp = 5;
};
can.save();
can.translate(250, 250);
can.rotate(i * 6 * Math.PI / 180);
can.beginPath();
/*can.moveTo(0, -80);
can.lineTo(0, -90);*/
if (temp == 4) {
can.moveTo(0, -75);
can.lineTo(0, -90);
} else {
can.moveTo(0, -80);
can.lineTo(0, -90);
};
can.closePath();
can.stroke();
can.restore();
};
//时针
can.save();
can.translate(250, 250);
can.rotate(oDate.getHours() * 30 * Math.PI / 180);
can.beginPath();
can.moveTo(0, 3);
can.lineTo(0, -35);
can.closePath();
can.strokeStyle = 'pink';
can.stroke();
can.restore();
//分针
can.save();
can.translate(250, 250);
can.rotate(oDate.getMinutes() * 6 * Math.PI / 180);
can.beginPath();
can.moveTo(0, 7);
can.lineTo(0, -70);
can.closePath();
can.strokeStyle = 'pink';
can.stroke();
can.restore();
//秒针
can.save();
can.translate(250, 250);
can.rotate(oDate.getSeconds() * 6 * Math.PI / 180);
can.beginPath();
can.moveTo(0, 7);
can.lineTo(0, -90);
can.closePath();
can.strokeStyle = 'pink';
can.stroke();
can.restore();
};
var timer = setInterval(draw, 1000);
</script>
</body>
</html>