MarseyWorld/files/assets/js/fireworks.js

38 lines
878 B
JavaScript
Raw Normal View History

2022-07-16 21:00:02 +00:00
const fireworks = document.getElementsByClassName("firework")
var counter = 0
for (let firework of fireworks){
var timeout = 2000 * counter
counter++
setTimeout(() => {
setInterval(() => {
firework.firstElementChild.src = "/i/firework-trail.webp"
var xpos = Math.floor(Math.random() * 80) + 5
var ypos = 95
firework.style.top=ypos+"%"
firework.style.left=xpos+"%"
2022-09-04 23:15:37 +00:00
2022-07-16 21:00:02 +00:00
firework.style.display="inline-block"
var hue = Math.floor(Math.random()*360)+1
firework.style.filter="hue-rotate("+hue+"deg)"
2022-09-04 23:15:37 +00:00
2022-07-16 21:00:02 +00:00
var id = null
2022-09-04 23:15:37 +00:00
var height = Math.floor(Math.random()*60)+15
2022-07-16 21:00:02 +00:00
clearInterval(id);
id = setInterval(frame, 20);
2022-09-04 23:15:37 +00:00
2022-07-16 21:00:02 +00:00
var vnum = Math.floor(Math.random()*1000)
2022-09-04 23:15:37 +00:00
2022-07-16 21:00:02 +00:00
function frame() {
if (ypos <= height) {
clearInterval(id);
firework.firstElementChild.src = "/i/firework-explosion.webp?v="+vnum
} else {
2022-09-04 23:15:37 +00:00
ypos--;
2022-07-16 21:00:02 +00:00
firework.style.top=ypos+"%"
}
2022-09-04 23:15:37 +00:00
}
2022-07-16 21:00:02 +00:00
}, 5000)
}, timeout)
}