-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (43 loc) · 1.28 KB
/
Copy pathscript.js
File metadata and controls
53 lines (43 loc) · 1.28 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
50
51
52
53
var audio = document.getElementById("audio");
const toggleButton = document.getElementsByClassName('toggle-button')[0]
const navbarLinks = document.getElementsByClassName('navbar-links')[0]
toggleButton.addEventListener('click', ()=>{
navbarLinks.classList.toggle('active')
})
window.onscroll = function() {myFunction()};
let myMediaQuery = window.matchMedia('(max-width: 768px)');
function myFunction() {
if (myMediaQuery.matches){
if (document.documentElement.scrollTop > 2700) {
audio.play()
} else {
audio.pause()
}
}else{
if (document.documentElement.scrollTop > 1600) {
audio.play()
} else {
audio.pause()
}
}
}
window.onresize = function (){
audio.pause()
}
let index = 0,
interval = 1000;
const rand = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
const animate = star => {
star.style.setProperty("--star-left", `${rand(-10, 100)}%`);
star.style.setProperty("--star-top", `${rand(-40, 80)}%`);
star.style.animation = "none";
star.offsetHeight;
star.style.animation = "";
}
for(const star of document.getElementsByClassName("magic-star")) {
setTimeout(() => {
animate(star);
setInterval(() => animate(star), 2000);
}, index++ * (interval / 3))
}