Created
April 18, 2016 08:51
-
-
Save brandonsheppard/5061877644e9f63054beaa951136ae3e to your computer and use it in GitHub Desktop.
Parallax hover affect
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
onmousemove = function(e){ | |
var positionY = e.clientY / 50 | |
var positionX = e.clientX / 50 | |
// Adjust translate position for elements with parallaxTranslate class on mouse move. | |
var parallaxTranslate = document.querySelectorAll('.parallaxTranslate'), i; | |
for (i = 0; i < parallaxTranslate.length; ++i) { | |
parallaxTranslate[i].style.transform = 'translate(-' + positionX + 'px,-' + positionY + 'px)'; | |
} | |
// Adjust translate position for elements with parallaxTranslate class on mouse move. | |
var parallaxTranslateReverse = document.querySelectorAll('.parallaxTranslate-reverse'), i; | |
for (i = 0; i < parallaxTranslateReverse.length; ++i) { | |
parallaxTranslateReverse[i].style.transform = 'translate(' + positionX + 'px,' + positionY + 'px)'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment