Last active
August 10, 2020 11:27
-
-
Save iamkevingreen/446629dd44e423019212fd3016930716 to your computer and use it in GitHub Desktop.
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
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