Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created September 26, 2021 11:32
Show Gist options
  • Save smpnjn/1dbd3a22e80d3dd2bccab397e2a7ecb2 to your computer and use it in GitHub Desktop.
Save smpnjn/1dbd3a22e80d3dd2bccab397e2a7ecb2 to your computer and use it in GitHub Desktop.
document.querySelectorAll('.button').forEach(function(item) {
// Add on mouseenter
item.addEventListener('mouseenter', function(e) {
calculateAngle(e, this.querySelector('span'), this);
});
// Add on mousemove
item.addEventListener('mousemove', function(e) {
calculateAngle(e, this.querySelector('span'), this);
});
// Reset everything on mouse leave
item.addEventListener('mouseleave', function(e) {
let dropShadowColor = `rgba(0, 0, 0, 0.3)`
if(item.getAttribute('data-filter-color') !== null) {
dropShadowColor = item.getAttribute('data-filter-color')
}
item.querySelector('span').style.transform = `rotateY(0deg) rotateX(0deg) scale(1)`;
item.querySelector('span').style.filter = `drop-shadow(0 10px 15px ${dropShadowColor})`;
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment