Created
October 20, 2015 08:48
-
-
Save daviddarnes/1fbd9cc9a9d8e12a76e1 to your computer and use it in GitHub Desktop.
Parallax scrolling with JavaScript
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
// Parallax header content | |
window.onscroll = function emParallax() { | |
if(window.pageYOffset>1) { | |
document.getElementById("parallax").style["-webkit-transform"] = "translateY("+(window.pageYOffset/3)+"px)"; | |
} else { | |
document.getElementById("parallax").style["-webkit-transform"] = "translateY(0px)"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example CodePen for reference http://codepen.io/daviddarnes/pen/vNajoe