Skip to content

Instantly share code, notes, and snippets.

@acerus
Created June 22, 2021 19:41
Show Gist options
  • Save acerus/0a96535edf98734dfbd106ddc07d7a17 to your computer and use it in GitHub Desktop.
Save acerus/0a96535edf98734dfbd106ddc07d7a17 to your computer and use it in GitHub Desktop.
Simple parralax with lax.js
// parallax
import lax from 'lax.js';
const PARALLAX_ELEMENTS = document.getElementsByClassName('lax');
document.addEventListener('DOMContentLoaded', function() {
if (0 < PARALLAX_ELEMENTS.length) {
lax.init();
// Add a driver that we use to control our animations
lax.addDriver('scrollY', function() {
return window.scrollY;
});
// Add animation bindings to elements
lax.addElements('.lax', {
scrollY: {
translateY: [
['elInY', 'elCenterY', 'elOutY'],
{
576: [0, 0, 0], // no parallax on mobiles
900: [-20, 0, 20], // small parallax on tablets
1366: [-60, 0, 60]
}
]
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment