-
Notifications
You must be signed in to change notification settings - Fork 0
/
ripple.js
35 lines (29 loc) · 945 Bytes
/
ripple.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
class Ripple {
constructor() {
document.body.addEventListener('click', (e) => this.show(e));
document.body.addEventListener('mousemove', (e) => this.hasMove = e);
this.hasMove = false;
setInterval(() => {
if (this.hasMove) {
this.show(this.hasMove);
this.hasMove = false;
}
}, 100);
}
show(event) {
const div = document.createElement('div');
div.classList.add('ripple');
div.style.top = `${event.pageY}px`;
div.style.left = `${event.pageX}px`;
div.style.backgroundColor = Ripple.getRandomColor();
document.body.appendChild(div);
setTimeout(() => div.remove(), 1000);
}
static getRandomColor() {
const o = Math.round;
const r = Math.random;
const s = 255;
return `rgb(${o(r() * s)}, ${o(r() * s)}, ${o(r() * s)})`;
}
}
new Ripple();