-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
41 lines (31 loc) · 835 Bytes
/
demo.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
const state = {
hover: false,
audio: null
};
const audio = document.getElementById('audio');
audio.addEventListener('canplay', () => {
if (state.hover) {
audio.play();
}
state.audio = audio;
});
const intro = document.getElementById('intro');
const hoverItems = document.getElementsByClassName('hover-text');
function onOkOver() {
intro.style.color = 'black';
intro.classList.add('flag');
Array.from(hoverItems).forEach(item => item.classList.remove('hide'));
if (state.audio) {
state.audio.play();
}
state.hover = true;
}
function onOkOut() {
intro.style.color = '';
intro.classList.remove('flag');
Array.from(hoverItems).forEach(item => item.classList.add('hide'));
if (state.audio) {
state.audio.pause();
}
state.hover = false;
}