-
Notifications
You must be signed in to change notification settings - Fork 0
/
rTouch.js
29 lines (27 loc) · 1.09 KB
/
rTouch.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
document.addEventListener('DOMContentLoaded', function() {
var button = document.querySelectorAll('.ripple');
function makeRipple(e) {
let circle = document.createElement('div');
let circleColor = this.getAttribute('rColor');
if( circleColor != null) {circle.style.backgroundColor = circleColor}
let d = Math.max(this.clientWidth, this.clientHeight);
circle.classList.add('rippleCircle');
circle.style.width = circle.style.height = `${d}px`;
circle.style.top = e.offsetY - d/2 + 'px';
circle.style.left = e.offsetX - d/2 + 'px';
this.appendChild(circle);
}
for(let i = 0; i < button.length; i++) {
let mask = document.createElement('div');
mask.classList.add('rippleMask');
button[i].style.position = 'relative';
button[i].style.overflow = 'hidden';
button[i].style.outline = 'none';
button[i].appendChild(mask);
button[i].addEventListener('click', makeRipple);
button[i].addEventListener('animationend', function() {
let oldCircle = this.querySelector('.rippleCircle');
this.removeChild(oldCircle);
});
}
}, false);