-
-
Save Spellhammer/625f9ba2063c383c783bb77cd32e0395 to your computer and use it in GitHub Desktop.
mouse.motion.parallax.effect.js
This file contains 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
document.querySelectorAll('.mover').forEach( mover => { | |
if( window.angular ) return; | |
window.addEventListener('mousemove', (e) => { | |
if( !calculating ) { | |
var calculating = setTimeout( () => { | |
var divisor = mover.getAttribute('speed') ?? 32; | |
var windowMouseX = (e.clientX - (document.documentElement.clientWidth / 2)); | |
var windowMouseY = (e.clientY - (document.documentElement.clientHeight / 2)); | |
var computedCSS = ''; | |
var translateX = (windowMouseX / divisor) * -1; | |
var translateY = (windowMouseY / divisor) * -1; | |
computedCSS += 'transform: translateX(' + translateX + 'px) translateY(' + translateY + 'px);'; | |
mover.style.cssText = computedCSS; | |
clearTimeout(calculating); | |
}, 100); | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment