forked from itscodenation/int-u3l6-23-24-student-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
61 lines (49 loc) · 1.68 KB
/
events.js
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
// We have all of these actions below that we wants to tie to an event!
let hoverCard = document.querySelector('[data-secret="hover"]');
// 1. Add an event listener to reveal the image on hover.
// - The selector is hoverCard
// - The event type is mouseover
{
let image = document.querySelector('.hidden-image');
image.style.width = '100%';
image.style.height = '100%';
image.style.opacity = '1';
}
// 2. Add an event listener to make the image hidden again.
// - The selector is hoverCard
// - The event type is mouseout
{
let image = document.querySelector('.hidden-image');
image.style.width = '0';
image.style.height = '0';
image.style.opacity = '0';
}
const clickCard = document.querySelector('[data-secret="click"]');
// 3. Add an event listener to reveal and animate the shape on click.
// - The selector is clickCard
// - The event type is click
{
clickCard.classList.toggle('revealed');
}
const doubleClickCard = document.querySelector('[data-secret="double-click"]');
// 4. Add an event listener to enlarge the text on double click.
// - The selector is doubleClickCard
// - The event type is dblclick
{
doubleClickCard.classList.toggle('revealed');
}
const keypressCard = document.querySelector('[data-secret="keypress"]');
// 5. Add an event listener to shake the card on any keypress.
// - The selector is document
// - The event type is keydown
{
keypressCard.classList.add('revealed');
keypressCard.style.animation = "shake 0.5s";
}
// 6. Add an event listener to stop the shaking.
// - The selector is document
// - The event type is keyup
{
keypressCard.classList.remove('revealed');
keypressCard.style.animation = "";
}