Skip to content

Autoplay timeleft restart issue #7418

Closed Answered by SaidRasinlic
SaidRasinlic asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, I fixed it. Since stop never restarts time we start it initially and then just resume or stop based on entry.isIntersecting flag.

In case you encounter this issue this is a 100% working solution:

useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
if (swiperContainer) {
if (!swiperContainer.running) {
swiperContainer.autoplay.start();
}
swiperContainer.autoplay[entry.isIntersecting ? 'resume' : 'stop']();
}
},
{ threshold: 0.5 },
);
observer.observe(sectionRef.current);
return () => {
observer.unobserve(sectionRef.current);
};
}, [swiperContainer]);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SaidRasinlic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant
Converted from issue

This discussion was converted from issue #7414 on March 25, 2024 06:39.