-
Notifications
You must be signed in to change notification settings - Fork 0
/
0810-08-random-balls.html
54 lines (50 loc) · 1.48 KB
/
0810-08-random-balls.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
<!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>隨機圓形</title>
<style>
.rect {
position: relative;
width: 800px;
height: 600px;
border: 1px solid rgb(255, 255, 255);
background-color: rgb(217, 228, 252);
}
.ball {
position: absolute;
width: 50px;
height: 50px;
background-color: rgb(248, 121, 121);
border-radius: 50%;
border: 1px solid rgb(255, 255, 255);
}
</style>
</head>
<body>
<div class="rect">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
const rect = $('.rect');
for(let i=0; i<100; i++){
const b =$(`<div class="ball"></div>`);
const left = Math.floor(800*Math.random());
const top = Math.floor(600*Math.random());
const size = 20 + Math.floor(21*Math.random());
const h = Math.floor(360*Math.random());
b.css({
left,
top,
width: size,
height: size,
//backgroundColor: randomColor(),
backgroundColor: `hsl(${h},100%,50%)`,
});
rect.append(b);
}
</script>
</body>
</html>