-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (58 loc) · 1.67 KB
/
index.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
/**
* Add a css rule to the
* @param {string} ruleText The rule to add.
*/
function insertStyleSheetRule(ruleText) {
const sheets = document.styleSheets;
const sheet = sheets[sheets.length - 1];
sheet.insertRule(
ruleText,
sheet.hasOwnProperty('rules') ? sheet.rules.length : sheet.cssRules.length
);
}
/**
* Open a window from (x, y)
* @param {Node} window The window to open.
* @param {number} x
* @param {number} y
*/
function openWindow(window, x, y) {
const windows = document.querySelectorAll('.window');
windows.forEach((window) => {
window.style.zIndex -= 1;
});
window.style.zIndex = windows.length;
window.classList.add('open');
window.addEventListener('animationend', (e) => {
window.classList.remove('open');
});
// Set the animation coordinates
insertStyleSheetRule(`
@keyframes open {
0% {
-webkit-clip-path: circle(0% at ${x}px ${y}px);
clip-path: circle(0% at ${x}px ${y}px);
}
100% {
-webkit-clip-path: circle(150% at ${x}px ${y}px);
clip-path: circle(150% at ${x}px ${y}px);
}
}`);
}
window.onload = function() {
let i = 0;
const onclick = (e) => {
console.log(e);
e.preventDefault();
if (e.type === 'touchstart') {
e = e.touches[0];
}
document.body.style.setProperty('--mouse-y', e.clientY + 'px');
document.body.style.setProperty('--mouse-x', e.clientX + 'px');
const windows = document.querySelectorAll('.window');
openWindow(windows[i], e.clientX, e.clientY);
i = (i + 1) % windows.length;
};
document.body.addEventListener('touchstart', onclick, false );
document.body.addEventListener('click', onclick, false);
};