-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
49 lines (39 loc) · 1.31 KB
/
Copy pathjs.js
File metadata and controls
49 lines (39 loc) · 1.31 KB
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
document.querySelectorAll('a').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const href = this.href;
document.body.style.transition = 'opacity 0.7s ease-in-out';
document.body.style.opacity = '0';
setTimeout(() => {
window.location.href = href;
}, 700); // match your transition duration
});
});
window.addEventListener('pageshow', function(e) {
if (e.persisted) {
document.body.style.transition = '';
document.body.style.opacity = '0';
requestAnimationFrame(() => {
document.body.style.transition = 'opacity 0.7s ease-in-out';
document.body.style.opacity = '1';
});
}
});
// Sounds!!
function playSound(src) {
const audio = new Audio(src);
audio.play();
}
// Button sounds
const isMobile = window.matchMedia('(pointer: coarse)').matches;
if (isMobile) {
document.querySelectorAll('a').forEach(link => {
link.addEventListener('touchstart', () => playSound('sounds/mobile-click.mp3'), { passive: true });
});
}
else {
document.querySelectorAll('a').forEach(link => {
link.addEventListener('mousedown', () => playSound('sounds/click.mp3'));
link.addEventListener('mouseup', () => playSound('sounds/unclick.mp3'));
});
}