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