Ripple press
A wave spreads from exactly where you pressed.
Click or tap anywhere on the button, or focus it and press Enter / Space.
<button class="rbtn">Press me</button>
<style>
.rbtn{position:relative;overflow:hidden}
.rbtn i{position:absolute;border-radius:50%;background:#fff8;
pointer-events:none;transform:scale(0);
animation:r .6s ease-out forwards}
@keyframes r{to{transform:scale(1);opacity:0}}
</style>
<script>
const b=document.querySelector('.rbtn');
function wave(x,y){
const s=Math.max(b.offsetWidth,b.offsetHeight)*2,
i=document.createElement('i');
i.style.cssText=`width:${s}px;height:${s}px;left:${x-s/2}px;top:${y-s/2}px`;
b.append(i);i.onanimationend=()=>i.remove();
}
b.onpointerdown=e=>{const r=b.getBoundingClientRect();
wave(e.clientX-r.left,e.clientY-r.top)};
b.onkeydown=e=>{if((e.key==='Enter'||e.key===' ')&&!e.repeat)
wave(b.offsetWidth/2,b.offsetHeight/2)};
</script>
Magnetic hover
The button leans toward your cursor, up to 18px.
Move near it, or drag on touch. When it has focus, nudge it with ←↑→↓ and press Esc to reset.
<div class="zone" style="padding:40px">
<button class="mbtn">Hover near me</button>
</div>
<style>.mbtn{transition:transform .25s}</style>
<script>
const m=document.querySelector('.mbtn'),max=18;let x=0,y=0;
const go=(a,b)=>{x=Math.max(-max,Math.min(max,a));
y=Math.max(-max,Math.min(max,b));
m.style.transform=`translate(${x}px,${y}px)`};
const z=m.parentElement;
z.onpointermove=e=>{const r=m.getBoundingClientRect();
go((e.clientX-(r.left+r.width/2-x))*.35,
(e.clientY-(r.top+r.height/2-y))*.35)};
z.onpointerleave=()=>go(0,0);
m.onkeydown=e=>{const d={ArrowLeft:[-6,0],ArrowRight:[6,0],
ArrowUp:[0,-6],ArrowDown:[0,6]}[e.key];
if(d){e.preventDefault();go(x+d[0],y+d[1])}
if(e.key==='Escape')go(0,0)};
m.onblur=()=>go(0,0);
</script>
Success checkmark
A save button that morphs, spins, then draws a check.
Click, tap, or press Enter. It resets itself after 2 seconds.
<button class="sbtn" data-state="idle"><span>Save</span>
<svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
</button>
<style>
.sbtn{position:relative;width:160px;height:48px;
transition:width .3s,border-radius .3s,background .3s}
.sbtn span{transition:opacity .2s}
.sbtn svg{position:absolute;inset:0;margin:auto;width:24px;
fill:none;stroke:#fff;stroke-width:3;
stroke-dasharray:24;stroke-dashoffset:24}
.sbtn[data-state=done]{width:48px;border-radius:24px;background:#3ecf8e}
.sbtn[data-state=done] span{opacity:0}
.sbtn[data-state=done] svg{stroke-dashoffset:0;
transition:stroke-dashoffset .4s .3s}
</style>
<script>
const s=document.querySelector('.sbtn');
s.onclick=()=>{if(s.dataset.state!=='idle')return;
s.dataset.state='done';
setTimeout(()=>s.dataset.state='idle',2000)};
</script>