-
Notifications
You must be signed in to change notification settings - Fork 30
/
rip.js
34 lines (32 loc) · 935 Bytes
/
rip.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
CSS.paintWorklet.addModule(
"https://googlechromelabs.github.io/css-paint-polyfill/ripple-worklet.js"
);
if (!window.performance) window.performance = { now: Date.now.bind(Date) };
function ripple(evt) {
let button = this,
rect = button.getBoundingClientRect(),
x = evt.clientX - rect.left,
y = evt.clientY - rect.top,
start = performance.now();
button.classList.add("animating");
requestAnimationFrame(function raf(now) {
let count = Math.floor(now - start);
button.style.cssText =
"--ripple-x: " +
x +
"; --ripple-y: " +
y +
"; --animation-tick: " +
count +
";";
if (count > 1200) {
button.classList.remove("animating");
button.style.cssText = "--animation-tick: 0;";
return;
}
requestAnimationFrame(raf);
});
}
[].forEach.call(document.querySelectorAll(".ripple"), function(el) {
el.addEventListener("click", ripple);
});