-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE34.html
More file actions
85 lines (84 loc) · 2.31 KB
/
E34.html
File metadata and controls
85 lines (84 loc) · 2.31 KB
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
<!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">
<style>
.container{
display: flex;
margin: 120px;
padding: 120px;
}
.ball{
position: relative;
width: 100px;
height: 100px;
background:purple;
border-radius: 100px;
margin: 100 px;
}
.height{
position: relative;
margin: 0;
padding: 30px
}
.btnBounce {
background-color: blue;
border: solid;
border-color: black;
color: white;
padding: 15px 50px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="ball">
<p class="height">10.0 m</p>
</div>
</div>
<button class='btnBounce'>Start the fall</button>
<script >
let button = document.querySelector('.btnBounce');
let text = document.querySelector('.height');
let g = -9.8, y = 0;
button.addEventListener('click', bouncing);
function bouncing(){
let v0 = 0,
s0 = 10,
t = 0,
H = 9;
y = 0;
let step = setInterval(falling, 50);
let ball = document.querySelector('.ball');
function falling(){
y = pos(t,v0,s0);
if (y<=0){
t = 0;
v0 = Math.sqrt(-2*H*g);
s0 = 0;
H--;
y=0;
if (H < 0){
clearInterval(step);
button.style.display = 'block';
}
}
ball.style.top = 100-10*y + 'px'
text.textContent = `${String(y).substring(0,3)} m`
t++;
}
function pos(t,v0,s0){
return (g*(t**2))/2 + v0*t + s0;
}
}
</script>
</body>
</html>