-
Notifications
You must be signed in to change notification settings - Fork 0
/
0810-13-circle-move.html
71 lines (63 loc) · 1.77 KB
/
0810-13-circle-move.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width, initial-scale=1.0">
<title>環狀排列 1</title>
<style>
.rect {
position: relative;
width: 800px;
height: 700px;
border: 1px solid gray;
background-color: darkcyan;
}
.ball {
position: absolute;
width: 50px;
height: 50px;
color: rgb(0, 0, 0);
background-color: rgb(131, 251, 255);
border: 1px solid olivedrab;
border-radius: 50%;
text-align: center;
line-height: 50px;
transition: 400ms;
}
</style>
</head>
<body>
<div class="rect">
<!-- <div class="ball"></div> -->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
const rect =$('.rect'); //設定參照 (reference)
const ballNum = 12;
const angUnit = Math.PI*2/ballNum;
//一圈360度=2π=PI*2
const balls = [];
for(let i=0; i<ballNum; i++){
const b = $(`<div class="ball">${i+1}</div>`);
b.css({
left: 400 -25,
top: 300 -25,
});
balls.push(b);
rect.append(b);
}
for(let i=0; i<ballNum; i++){
setTimeout(()=>{
const b = balls[i];
b.css({
left: 400 -25 + 250 * Math.cos(i*angUnit),
top: 300 -25 + 250 * Math.sin(i*angUnit)
});
}, 200*i);
}
//cos X軸
//sin Y軸
</script>
</body>
</html>