-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path48.setTimeOut-ball.html
51 lines (45 loc) · 1.26 KB
/
48.setTimeOut-ball.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.rect {
position: relative;
width: 800px;
height: 600px;
background-color: rgb(248, 232, 232);
border: 1px solid black;
}
.ball {
position: absolute;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: rgb(245, 52, 52);
color: white;
font-weight: 800;
line-height: 50px;
text-align: center;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="rect">
<div class="ball" style="left: 0px">7</div>
</div>
<script>
const rect = document.querySelector(".rect");
const ball = document.querySelector(".ball");
const doRun = () => {
let left = parseInt(ball.style.left) + 3 + "px";
ball.style.left = left;
setTimeout(doRun, 30);
}
doRun();
</script>
</body>
</html>