-
Notifications
You must be signed in to change notification settings - Fork 0
/
my.js
64 lines (45 loc) · 1.49 KB
/
my.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
62
63
window.saveDataAcrossSessions = true;
const loader = document.querySelector('.loader');
const outerLoader = document.querySelector('.outer-loader');
const app = document.querySelector('.app');
const musicboxes = app.querySelectorAll('.music');
setTimeout(() => {
loader.classList.add('removed');
loader.addEventListener('transitionend', () => {
loader.remove();
outerLoader.remove();
});
}, 4000);
const audios = new Array(musicboxes.length);
for(let i = 0; i < musicboxes.length; ++i)
audios[i] = new Audio("sounds/" + (i + 1) + ".wav");
// console.log(audios);
musicboxes.forEach((musicBox, idx) => musicBox.id = "box" + String(idx));
app.addEventListener('click', e => {
if(e.target && e.target.classList.contains('music')) {
showPlaying(e.target);
const id = parseInt(e.target.id.substr(3));
audios[id].play();
}
});
function showPlaying(musicBox) {
musicBox.classList.add('playing');
setTimeout(() => {
musicBox.classList.remove('playing');
}, 1200);
}
webgazer.setGazeListener((data, _timestamp) => {
if(data == null)
return;
const currentlySeeingElement = document.elementFromPoint(data.x, data.y);
if(currentlySeeingElement == null)
return;
if(!currentlySeeingElement.classList.contains("music"))
return;
const idString = currentlySeeingElement.id.substr(3); // eg: 'box12' -> '12'
const id = parseInt(idString);
if(audios[id] && audios[id].paused) {
showPlaying(currentlySeeingElement);
audios[id].play();
}
}).begin();