Skip to content

Instantly share code, notes, and snippets.

@brandonsheppard
Created April 18, 2016 08:51
Show Gist options
  • Save brandonsheppard/5061877644e9f63054beaa951136ae3e to your computer and use it in GitHub Desktop.
Save brandonsheppard/5061877644e9f63054beaa951136ae3e to your computer and use it in GitHub Desktop.
Parallax hover affect
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