Cannot immediately stop slider #6618
Unanswered
SyntaxSamurai43
asked this question in
Q&A
Replies: 3 comments 3 replies
-
I need this too! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Same issue with Swiper 8.3.2 these are options I use
tried to go and tried to use code provided above |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is how I solved it with Swiper 11. let duration: number;
let distanceRatio: number;
const stopAutoplay = () => {
// Stop slide at current translate.
swiper.setTranslate(swiper.getTranslate());
// Calculating the distance between current slide and next slide.
// 0.3 is equal to 30% distance to the next slide.
distanceRatio = Math.abs((swiper.width * swiper.activeIndex + swiper.getTranslate()) / swiper.width);
// The duration that playing to the next slide
duration = swiper.params.speed! * distanceRatio;
swiper.autoplay.stop();
};
let startTimer: ReturnType<typeof setTimeout>;
const startAutoplay = (delay = duration) => {
if (startTimer) clearTimeout(startTimer);
startTimer = setTimeout(() => {
swiper.autoplay.start();
// 400 => Solve the problem that cannot slide prev continuously during autoplay
}, delay + 400);
};
const isPlaying = ref(true);
let clickable = true;
const handleTogglePlay = () => {
if (!clickable) return;
clickable = false;
if (isPlaying.value) stopAutoplay();
else {
const distance = swiper.width * swiper.activeIndex + swiper.getTranslate();
// Avoid distance that is exactly 0
duration = distance !== 0 ? duration : 0;
swiper.slideTo(swiper.activeIndex, duration);
startAutoplay();
}
isPlaying.value = !isPlaying.value;
setTimeout(() => { clickable = true; }, 200);
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Check that this is really a bug
Reproduction link
https://jsfiddle.net/30xakfyr/
Bug description
I cannot immediately stop the slider with the code below. It waits until the slide is done but the speed is 6000 so that takes a long time before the slider stops. Can you please fix this. On the internet there are lots of other pages where this problem is described.
See the issue here:
https://jsfiddle.net/30xakfyr/
Expected Behavior
No response
Actual Behavior
No response
Swiper version
v9.2.4
Platform/Target and Browser Versions
All
Validations
Would you like to open a PR for this bug?
Beta Was this translation helpful? Give feedback.
All reactions