Created
January 16, 2017 11:44
-
-
Save manfromanotherland/4a8c117e7cf27cab2e53ae11edcb371f to your computer and use it in GitHub Desktop.
JS: Variable scroll speeds with JavaScript › http://callmenick.com/post/advanced-parallax-scrolling-effect
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
(function(){ | |
var parallax = document.querySelectorAll(".parallax"), | |
speed = 0.5; | |
window.onscroll = function(){ | |
[].slice.call(parallax).forEach(function(el,i){ | |
var windowYOffset = window.pageYOffset, | |
elBackgrounPos = "50% " + (windowYOffset * speed) + "px"; | |
el.style.backgroundPosition = elBackgrounPos; | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment