-
Notifications
You must be signed in to change notification settings - Fork 2
/
circle.html
65 lines (58 loc) · 1.56 KB
/
circle.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆周运动</title>
<style>
.circle {
width: 10px;
height: 10px;
background-color: gray;
position: absolute;
left: 300px;
top: 300px;
}
.dot {
border: 1px solid #000;
position: absolute;
}
.wrap {
width: 200px;
height: 200px;
border: 1px solid red;
border-radius: 50%;
position: absolute;
left: 100px;
top: 100px;
}
</style>
</head>
<body>
<div class="wrap"></div>
<div class="circle"></div>
<script src="./lib/jquery-2.0.3.js"></script>
<script>
var r = 100
var $circle = $('.circle')
var $wrap = $('.wrap')
var ang = 0
function draw() {
ang++
var a = Math.cos(ang * (Math.PI / 180)) * r
var b = Math.sin(ang * (Math.PI / 180)) * r
var left = $wrap.offset().left
var top = $wrap.offset().top
// console.log(left, top, a, b)
$circle.css({
left: left + r + a,
top: top + r - b
})
// 使用requestAnimationFrame会更加流畅,相比setInterval
window.requestAnimationFrame(draw)
}
draw()
</script>
</body>
</html>