forked from wesbos/beginner-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-loop.html
94 lines (77 loc) · 2.06 KB
/
event-loop.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
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
86
87
88
89
90
91
92
93
94
<!-- eslint-disable prefer-arrow-callback -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Event Loop</title>
<link rel="stylesheet" href="../base.css">
</head>
<body>
<style>
.go {
margin: 5rem;
background: white;
padding: 5rem;
width: 25rem;
height: 25rem;
transition: all 0.2s;
}
.go.circle {
border-radius: 50%;
}
.go.red {
background: red;
}
.go.purple {
color: white;
background: purple;
}
.go.fadeOut {
opacity: 0;
}
</style>
<div class="go">Click Me</div>
<script>
// eslint-disable prefer-arrow-callback
// console.log('Starting');
// setTimeout(() => {
// console.log('Running...');
// }, 2000);
// console.log('Ending');
const go = document.querySelector('.go');
// Change text to 'Go' when clicked
go.addEventListener('click', (e) => {
const element = e.currentTarget;
console.log(element);
element.textContent = 'GO!';
// Make it a circle after 2 seconds
setTimeout(() => {
console.log('Transforming to circle');
element.classList.add('circle');
// Make it red after 0.5 seconds
setTimeout(() => {
console.log('Becoming red');
element.classList.add('red');
// Make it square after 0.25 seconds
setTimeout(() => {
console.log('Back to square');
element.classList.remove('circle');
// Make it purple after 0.3 seconds
setTimeout(() => {
console.log('Becoming purple');
element.classList.remove('red');
element.classList.add('purple');
// Fade out after 0.3 seconds
setTimeout(() => {
console.log('Fading out');
element.classList.add('fadeOut');
}, 500);
}, 300);
}, 250);
}, 500);
}, 2000);
});
</script>
</body>
</html>