Created
August 29, 2020 17:10
-
-
Save wpflames/be391bdd8f056839d0c76d8f3e855e05 to your computer and use it in GitHub Desktop.
Button with Direction Aware Hover Effect - JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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