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