min30327 / luxy.js

Inertia scroll and parallax effect plugin in Vanilla.js
596 stars 86 forks source link

Updating the Targets for new PJAX Page Load #2

Closed bradleyDouglas closed 5 years ago

bradleyDouglas commented 5 years ago

Hello.

I'm currently using Luxy in combination with SWUP. I'm trying to figure out what the best approach is for updating Luxy Targets on a new PJAX Page load. Currently, my home page (or whatever page is loaded first) works as expected and the 'luxy-el' have a nice parallax effect to them. However, when I navigate to another page, the 'luxy-el' don't update.

Is it as simple as re-initializing Luxy on each load or is there a better approach to just updating the Targets?

Thanks!

min30327 commented 5 years ago

I haven't used Swup, but I saw Swup's document. You solve the problem by binding both the DOMContentLoaded and swup:contentReplaced or swup:animationInDone events?

document.addEventListener('DOMContentLoaded', event => {
    luxy.init();
});
document.addEventListener('swup:contentReplaced', event => {
    luxy.init();
});
bradleyDouglas commented 5 years ago

Yeah, that's what I implemented and it works great. Was just wondering if there was maybe a way to just update the targets, but it works fine this way.

Thanks! I'm currently using Luxy on two sites and I'm loving it.

min30327 commented 5 years ago

Thank you for using. I will try to make it better. Closed this issue, as solved the problem.

ItayAssouline commented 3 years ago

I haven't used Swup, but I saw Swup's document. You solve the problem by binding both the DOMContentLoaded and swup:contentReplaced or swup:animationInDone events?

document.addEventListener('DOMContentLoaded', event => {
    luxy.init();
});
document.addEventListener('swup:contentReplaced', event => {
    luxy.init();
});

It didnt work for me, any idea why?