Created
March 8, 2018 22:51
-
-
Save AndrwM/e63abf2d5d8498f1e7a8794de039f1da to your computer and use it in GitHub Desktop.
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
| const $parallaxItems = $('[js-parallax]'); | |
| const parallaxSpeed = -0.04; | |
| if ($parallaxItems.length > 0) { | |
| $parallaxItems.css('will-change', 'transform'); | |
| window.addEventListener('scroll', function() { | |
| $parallaxItems.css('transform', 'translateY( calc(' +(document.body.scrollTop || document.documentElement.scrollTop) * parallaxSpeed+ '* 1px ) )'); | |
| }); | |
| } | |
| // Improvements: use request animation here: https://codepen.io/davatron5000/pen/YeyOxQ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment