Last active
December 22, 2015 03:29
-
-
Save bbrks/6410920 to your computer and use it in GitHub Desktop.
Super simple parallax scrolling
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 speed = 4.0; | |
var ypos = -window.pageYOffset / speed + "px"; | |
var xpos = "50%"; | |
var elems = document.getElementsByClassName('parallax'); | |
for (var i = elems.length - 1; i >= 0; i--) { | |
elems[i].style.backgroundPosition = xpos +" "+ ypos; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment