Created
June 22, 2021 19:41
-
-
Save acerus/0a96535edf98734dfbd106ddc07d7a17 to your computer and use it in GitHub Desktop.
Simple parralax with lax.js
This file contains 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
// 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