Skip to content

Instantly share code, notes, and snippets.

@AndrwM
Created March 8, 2018 22:51
Show Gist options
  • Select an option

  • Save AndrwM/e63abf2d5d8498f1e7a8794de039f1da to your computer and use it in GitHub Desktop.

Select an option

Save AndrwM/e63abf2d5d8498f1e7a8794de039f1da to your computer and use it in GitHub Desktop.
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