Skip to content

Instantly share code, notes, and snippets.

@iamkevingreen
Created June 2, 2016 13:19
Show Gist options
  • Save iamkevingreen/82971e720559fae028efa8413fdbfd44 to your computer and use it in GitHub Desktop.
Save iamkevingreen/82971e720559fae028efa8413fdbfd44 to your computer and use it in GitHub Desktop.
let scrollPosition = 0;
let setPosition = () => {
if (window.pageYOffset !== undefined) {
scrollPosition = window.pageYOffset;
} else {
scrollPosition = (document.documentElement || document.body.parentNode || document.body).scrollTop;
}
};
let parallax = (el, divisble) => {
setPosition();
el.style.transform = "translate3d(0px, "+(scrollPosition / divisble)+"px, 0px)";
}
let handleScrolling = () => {
parallax(imageFloatOne, -6);
parallax(imageFloatTwo, -4.3);
parallax(imageFloatThree, -2);
parallax(earnedImageTwo, -6);
parallax(sparkText, -13);
parallax(heroText, -13);
}
window.addEventListener('scroll', handleScrolling);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment