-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathripple.js
27 lines (22 loc) · 1.1 KB
/
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
function RippleElement(element = ".ripple") {
document.querySelectorAll(element).forEach((el) => {
if(!el.classList.contains("ripple")) el.classList.add("ripple");
el.addEventListener("click", (e) => {
var RippleElement = document.createElement("div");
RippleElement.className = "ripple-effect";
if (e.target.getAttribute("data-ripple-color").length > 0)
RippleElement.style.setProperty("--ripple-background", e.target.getAttribute("data-ripple-color"));
e.target.appendChild(RippleElement);
e = e.touches ? e.touches[0] : e;
const r = el.getBoundingClientRect(),
d = Math.sqrt(Math.pow(r.width, 2) + Math.pow(r.height, 2)) * 2;
RippleElement.style.cssText = `--s: 0; --o: 1;`;
RippleElement.offsetTop;
RippleElement.style.cssText = `--t: 1; --o: 0; --d: ${d}; --x:${e.clientX - r.left
}; --y:${e.clientY - r.top};`;
setTimeout(function () {
RippleElement.remove("ripple");
}, 600);
});
});
}