Skip to content

Instantly share code, notes, and snippets.

@manfromanotherland
Created January 16, 2017 11:44
Show Gist options
  • Save manfromanotherland/4a8c117e7cf27cab2e53ae11edcb371f to your computer and use it in GitHub Desktop.
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
(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