Created
March 1, 2018 11:44
-
-
Save neonicotinoid/2093fa2eeec81bd572f2ae7fdb9c9120 to your computer and use it in GitHub Desktop.
Smooth parallax on vanilla JS
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
window.onscroll = function () { | |
var scrollBarPosition = window.pageYOffset | document.body.scrollTop; | |
var parallax = scrollBarPosition / 40; | |
parallaxEl = document.querySelector('.class-name'); | |
parallaxEl.style.transform = 'translate3d(0px, ' + parallax + '%, .01px)'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment