Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created August 29, 2020 17:10
Show Gist options
  • Select an option

  • Save wpflames/be391bdd8f056839d0c76d8f3e855e05 to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/be391bdd8f056839d0c76d8f3e855e05 to your computer and use it in GitHub Desktop.
Button with Direction Aware Hover Effect - JS
const buttons = document.querySelectorAll('a');
buttons.forEach(btn => {
btn.addEventListener('mouseenter', function(e){
let x = e.clientX - e.target.offsetLeft;
let y = e.clientY - e.target.offsetTop;
let ripples = document.createElement('span');
ripples.style.left = x + 'px';
ripples.style.top = y + 'px';
this.appendChild(ripples);
setTimeout(() => {
ripples.remove()
}, 1000)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment