Repository navigation
Expand file tree
/
Copy pathrocket.html
More file actions
59 lines (59 loc) · 1.38 KB
/
Copy pathrocket.html
File metadata and controls
59 lines (59 loc) · 1.38 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
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rocket Sample</title>
<style>
.rocketArea {
position: relative;
background: darkblue;
min-height: 50px;
}
#rocket {
position: absolute;
top: 5px;
left: 0px;
transition: left 0.5s;
}
.buttons {
margin-top: 1em;
display: flex;
gap: 1em;
font-size: 140%;
}
</style>
</head>
<body>
<div class="rocketArea">
<img
id="rocket"
src="images/rocket-147466_640.png"
height="40"
alt="Rocket"
/>
</div>
<div class="buttons">
<button type="button" id="moveLeft" onclick="moveLeft()">◄</button>
<button type="button" id="moveRight" onclick="moveRight()">
►
</button>
</div>
<script>
let position = 0
const rocket = document.getElementById('rocket')
const max = window.innerWidth - rocket.clientWidth
function moveLeft() {
if (position > 0) {
position -= 10
rocket.style.left = position + 'px'
}
}
function moveRight() {
if (position + 10 <= max) {
position += 10
rocket.style.left = position + 'px'
}
}
</script>
</body>
</html>