Skip to content

Instantly share code, notes, and snippets.

@iamkevingreen
Last active August 10, 2020 11:27
Show Gist options
  • Save iamkevingreen/446629dd44e423019212fd3016930716 to your computer and use it in GitHub Desktop.
Save iamkevingreen/446629dd44e423019212fd3016930716 to your computer and use it in GitHub Desktop.
let Parallax = {
init(el, displace) {
this.animateItem(el, displace);
},
setPosition() {
if (window.pageYOffset !== undefined) {
return window.pageYOffset;
} else {
return (document.documentElement || document.body.parentNode || document.body).scrollTop;
}
},
animateItem(el, displace) {
if (typeof window.orientation !== 'undefined') { return; }
let scrollPosition = this.setPosition();
el.style.transform = "translate3d(0px, "+(scrollPosition / displace)+"px, 0px)";
}
}
export default Parallax;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment