-
Notifications
You must be signed in to change notification settings - Fork 5
/
animation.html
49 lines (42 loc) · 1.15 KB
/
animation.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
<!DOCTYPE html>
<p id="square">
</p>
<ol>
<li>Press and hold the Shift key for three seconds until the square has stopped moving (right side of the page)</li>
<li>Release the Shift key to make the square start to move to the left</li>
<li>Press and hold the Shift key before the square stops moving (0–2 seconds after releasing)</li>
</ol>
<p><strong>Bug</strong>: On Firefox, after completing step 3, the square will instantly snap to the right instead of slowly moving to the right</p>
<script>
document.addEventListener('keydown', function() {
if (event.key === "Shift") {
document.getElementById("square").classList.add("move");
}
});
document.addEventListener('keyup', function() {
if (event.key === "Shift") {
document.getElementById("square").classList.remove("move");
}
});
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
#square {
width: 100px;
height: 100px;
background-color: black;
transition-duration: 3s;
}
.move {
transform: translateX(calc(100vw - 100px));
}
ol {
margin-top: 20px;
margin-left: 20px;
}
</style>