Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Created October 20, 2015 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddarnes/1fbd9cc9a9d8e12a76e1 to your computer and use it in GitHub Desktop.
Save daviddarnes/1fbd9cc9a9d8e12a76e1 to your computer and use it in GitHub Desktop.
Parallax scrolling with JavaScript
// 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)";
}
}
@daviddarnes
Copy link
Author

Example CodePen for reference http://codepen.io/daviddarnes/pen/vNajoe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment