-
Notifications
You must be signed in to change notification settings - Fork 0
/
ripink.js
73 lines (65 loc) · 2.63 KB
/
ripink.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var ripink = function(){}
ripink.apply = function(ELEMENTS, COLOR) {
var STYLE = ELEMENTS + " {overflow:hidden;position:relative} "+ELEMENTS+" .js-ripink-ink{display:block;position:absolute;background:" + COLOR + ";border-radius:100%;transform:scale(0)} "+ELEMENTS+" .js-ripink-ink.js-ripink-animate {animation: js-ripink-ripple 0.65s linear;} @keyframes js-ripink-ripple {100% {opacity: 0.25; transform: scale(2.5);}";
head = document.head || document.getElementsByTagName('head')[0];
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = STYLE;
} else {
style.appendChild(document.createTextNode(STYLE));
}
head.appendChild(style);
var parent, ink, d, x, y;
dfe(ELEMENTS, function(el) {
el.addEventListener("mousedown", function(e) {
parent = el.parentNode;
el.insertBefore(mhe("<span class='js-ripink-ink'></span>"), el.firstChild);
ink = el.querySelector(".js-ripink-ink");
ink.setAttribute("data-js-ripink-active", "start");
ink.classList.remove("js-ripink-animate");
d = String(Math.max(el.offsetWidth, el.offsetHeight)) + "px";
ink.style.width = d;
ink.style.height = d;
x = e.pageX - el.offsetLeft - ink.offsetWidth/2;
y = e.pageY - el.offsetTop - ink.offsetHeight/2;
x = String(x) + "px"; y = String(y) + "px";
ink.style.top = y; ink.style.left = x;
ink.classList.add("js-ripink-animate")
window.setTimeout(function() {
if(ink.getAttribute("data-js-ripink-active") == "stop")
{
return;
}
ink.setAttribute("data-js-ripink-active", "stop");
ink.style.transform = "scale(2.5)";
ink.style.opacity = "0.25";
},650);
});
el.addEventListener("mouseup", function(e) {
ink = el.querySelector(".js-ripink-ink");
if(ink.getAttribute("data-js-ripink-active") != "stop")
{
ink.setAttribute("data-js-ripink-active", "stop");
return;
}
ink.parentNode.removeChild(ink);
})
});
}
function dfe(select, func)
{
els = document.querySelectorAll(select);
for(var i=0; i<els.length; i++)
{
el = els[i];
func(el);
}
}
function mhe(html)
{
var t = document.createElement('template');
t.innerHTML = html;
el = t.content.cloneNode(true);
return el;
}