<script src="../js/startMove.js"></script>
<script>
class Fireworks {
constructor(x, y) {
this.x = x;
this.y = y;
this.bh = document.body.offsetHeight;
this.upfire = document.createElement('div');
document.body.appendChild(this.upfire);
this.upfire.style.backgroundColor = 'rgb(' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ')';
this.upfire.style.top = this.bh - this.upfire.offsetHeight + 'px';
this.upfire.style.left = this.x + 'px';
this.upMove();
}
upMove() {
startMove(this.upfire, {
left: this.x,
top: this.y,
}, () => {
document.body.removeChild(this.upfire);
this.Crefires();
})
}
Crefires() {
for (let i = 0; i < 50; i++) {
this.fires = document.createElement('div');
document.body.appendChild(this.fires);
this.fires.style.backgroundColor = 'rgb(' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ',' + Math.floor(Math.random() * 256) + ')';
this.fires.style.top = this.y + 'px';
this.fires.style.left = this.x + 'px';
this.Boom(this.fires);
}
}
Boom(obj) {
let ix = this.x;
let iy = this.y;
var speedX = parseInt((Math.random() > 0.5 ? '-' : '') + this.Range(1, 15));
var speedY = parseInt((Math.random() > 0.5 ? '-' : '') + this.Range(1, 15));
obj.timer = setInterval(() => {
ix += speedX;
iy += speedY++;
if (iy > this.bh) {
document.body.removeChild(obj);
clearInterval(obj.timer)
};
obj.style.top = iy + 'px';
obj.style.left = ix + 'px';
}, 0)
}
Range(a, b) {
return Math.floor(Math.random() * (b - a) + a);
}
}
document.onmousedown = function (e) {
var evt = e || event;
var fireworks = new Fireworks(evt.clientX, evt.clientY);
}
</script>