Events fired when using tiny-slider #782
-
Hello everyone, Our team has successfully created 4 or 5 websites using Swup and we encountered and overcame most of the common issues associated with it. However, I'm currently working on a much larger project, and I'm facing a new challenge. I encountered two problems. I fixed one, but it doesn't solve the overlaying main issue where contentReplaced and willReplaceContent are being executed on the homepage after navigating back to it from any of the chapters. The problem is explained in this Loom I recorded here I also created a codesandbox here I would greatly appreciate any insights or suggestions you may have for addressing this issue. cc @andresclua |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @elisabetperez! Two things come to mind:
|
Beta Was this translation helpful? Give feedback.
-
The below code should work. I've made a few adjustments, namely to store the actual slider instances in the array, so you don't have to go by the array index, and removing the timeout. Also, the class Core {
contentReplaced() {
this.instances["SliderA"] = [];
document.querySelectorAll(".c--slider-a").forEach((element, index) => {
this.instances["SliderA"].push(new SliderA({ container: ".c--slider-a__wrapper", controls: ".c--slider-a__controls" }));
});
}
willReplaceContent() {
this.instances["SliderA"].forEach((instance) => instance.destroy());
}
} |
Beta Was this translation helpful? Give feedback.
Looks like it's an issue with the tiny-slider library you're using. It seems to not cancel its timeouts even when destroying the instance. Not sure if that can be fixed using timeouts or swup events. There's an open issue with a few workarounds, but hard to say whether that would help.