My goal is to integrate the npm package for parallax (lax.js) into my project. The documentation states that in order to initialize it, the following code snippet should be included:
window.onload = function () {
lax.init()
// Add a driver that we use to control our animations
lax.addDriver('scrollY', function () {
return window.scrollY
})
}
Since I plan on using lax in multiple locations within my project, I have created a separate JavaScript file to handle the functionality of each component. Thus, I added the above code snippet to the main JavaScript file that governs the entire webpage.
import lax from './lax.js';
import './component';
window.onload = function () {
lax.init()
// Add a driver that we use to control our animations
lax.addDriver('scrollY', function () {
return window.scrollY;
});
}
However, when attempting to utilize the lax object within the component.js file, an error stating that lax is not defined is encountered. This raises the question of the correct procedure for initializing in one file and using in another when working with a third-party package like lax.js.