-
-
Save trentmwillis/6d99bd456ea236cc207a to your computer and use it in GitHub Desktop.
A simple parallax effect on scroll
This file contains hidden or 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
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