forked from Rajspeaks/Hack-to-War-Ground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
floating_boat.html
57 lines (42 loc) · 869 Bytes
/
floating_boat.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
#boat {
margin-left: 0;
cursor: pointer;
transition: margin-left 3s ease-in-out;
}
/* flipping the picture with CSS */
.back {
transform: scaleX(-1);
filter: fliph;
}
</style>
<title>Floating Boat</title>
</head>
<body>
<img src="boat.png" id="boat">
<script>
boat.onclick = function() {
this.onclick = null;
let times = 1;
function go() {
if (times % 2) {
boat.classList.remove('back');
boat.style.marginLeft = 100 * times + 200 + 'px';
} else {
boat.classList.add('back');
boat.style.marginLeft = 100 * times - 200 + 'px';
}
}
go();
boat.addEventListener('transitionend', function() {
times++;
go();
});
}
</script>
</body>
</html>