Files
tiny-ripple/index.js
2025-08-20 00:27:36 -07:00

3 lines
1.7 KiB
JavaScript

if(window.__tinyRippleInit) throw new Error('tiny-ripple already initialized') window.__tinyRippleInit = true var __tr_style = document.createElement('style') __tr_style.textContent = ".r{position:fixed;border-radius:50%;pointer-events:none;background:transparent;box-shadow:0 8px 18px rgba(0,0,0,0.14);transform:translate(-50%,-50%) scale(.15);opacity:1;transition:transform .42s cubic-bezier(.2,.8,.2,1),opacity .42s linear,box-shadow .42s linear;z-index:9999999}.r.a{transform:translate(-50%,-50%) scale(1);opacity:0;box-shadow:0 0 0 rgba(0,0,0,0)}" document.head.appendChild(__tr_style) var __tr_dur = 420 function __tr_make(x,y){var dx=Math.max(x,innerWidth-x),dy=Math.max(y,innerHeight-y),r=Math.hypot(dx,dy),s=Math.max(48,Math.ceil(r*2));var e=document.createElement('div');e.className='r';e.style.width=e.style.height=s+'px';e.style.left=x+'px';e.style.top=y+'px';document.body.appendChild(e);void e.offsetWidth;e.classList.add('a');setTimeout(function(){if(e.parentNode) e.parentNode.removeChild(e)},__tr_dur+60)} var __tr_h = function(ev){var x=('clientX' in ev && ev.clientX!=null)?ev.clientX:(ev.touches&&ev.touches[0]&&ev.touches[0].clientX)||0;var y=('clientY' in ev && ev.clientY!=null)?ev.clientY:(ev.touches&&ev.touches[0]&&ev.touches[0].clientY)||0;__tr_make(x,y)} if(window.PointerEvent) addEventListener('pointerdown',__tr_h,{passive:true}); else{addEventListener('touchstart',__tr_h,{passive:true});addEventListener('mousedown',__tr_h,{passive:true})} window.tinyRipple={disable:function(){if(window.PointerEvent) removeEventListener('pointerdown',__tr_h);else{removeEventListener('touchstart',__tr_h);removeEventListener('mousedown',__tr_h)}if(__tr_style.parentNode) __tr_style.parentNode.removeChild(__tr_style);window.__tinyRippleInit=false}}