Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created February 7, 2018 14:41
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 juanbrujo/207c96fff510ca316ef4cd36b8b2f824 to your computer and use it in GitHub Desktop.
Save juanbrujo/207c96fff510ca316ef4cd36b8b2f824 to your computer and use it in GitHub Desktop.
const title = document.querySelector('h1.title');
const speed = 0.2;
title.style.transform = 'translateY( calc( var(--scrollparallax) * 1px ) )';
function setScrollParallax() {
title.style.setProperty("--scrollparallax", (document.body.scrollTop || document.documentElement.scrollTop) * speed);
window.requestAnimationFrame( setScrollParallax );
}
window.requestAnimationFrame( setScrollParallax );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment