ripples.js
ASCII text
1(() => { 2const rippleHosts = document.querySelectorAll('.button, button:not(.link-button), input, select, .navbar a, .navrail a'); 3 4function generateRipple(rippleX, rippleY, rippleDimensions) { 5const div = document.createElement('div'); 6div.className = 'ripple-pad'; 7 8div.style.width = `${rippleDimensions}px`; 9div.style.height = `${rippleDimensions}px`; 10 11div.style.left = `${rippleX}px`; 12div.style.top = `${rippleY}px`; 13 14div.style.borderRadius = `${rippleDimensions}px`; 15 16return div; 17} 18 19for (const host of rippleHosts) { 20host.addEventListener('mousedown', (event) => { 21const rect = host.getBoundingClientRect(); 22const cursorX = event.clientX; 23const cursorY = event.clientY; 24 25const fromTop = cursorY - rect.top; 26const fromBottom = rect.height - fromTop; 27const fromLeft = cursorX - rect.left; 28const fromRight = rect.width - fromLeft; 29 30const requiredDimension = Math.ceil(Math.max(fromRight, fromLeft, fromTop, fromBottom)); 31const ripple = generateRipple(fromLeft - requiredDimension, fromTop - requiredDimension, requiredDimension * 2); 32host.appendChild(ripple); 33 34ripple.addEventListener('animationend', ({ animationName }) => { 35if (animationName === 'RippleEffect') ripple.remove(); 36}); 37}); 38} 39})()