Skip to content

Instantly share code, notes, and snippets.

@trentmwillis
Created August 17, 2014 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentmwillis/6d99bd456ea236cc207a to your computer and use it in GitHub Desktop.
Save trentmwillis/6d99bd456ea236cc207a to your computer and use it in GitHub Desktop.
A simple parallax effect on scroll
var Plax = function() {
var plax = document.querySelectorAll('.plax');
for (var i=0; i<plax.length; i++) {
plax[i].style.position = 'fixed';
}
document.onscroll = function() {
for (var i=0; i<plax.length; i++) {
plax[i].style.top = (-plax[0].getAttribute('data-plax') * document.body.scrollTop) + 'px';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment