slickPause doesn't work
See original GitHub issueI’m trying to use the new feature slickPause
. However it doesn’t work.
Before this feature I was changing an autoPlay
state variable, so that the autoplay
prop change to false when the slider has to pause.
// this.state.autoPlay is true by default
pauseSlider() {
this.setState({autoPlay: false});
}
...
render() {
const {autoPlay} = this.state;
const settings = {
autoplaySpeed: 5000,
className: 'swiper-wrapper',
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
autoplay: autoPlay,
pauseOnHover: false,
initialSlide: 1,
beforeChange: this.beforeChangeSlide,
afterChange: this.afterChangeSlide
};
...
}
but the problem was that autoPlay
to false made to slide one more time (because the autoPlayTimer
was not cleared). Now, I expect the timer to be cleared when calling slickPause()
, but it seems to do nothing, as it works the same way as not calling it. I’ve tried several ways:
Keeping the above example and calling this.slider.slickPause()
from componentDidUpdate()
:
componentDidUpdate(prevProps, prevState) {
const {autoPlay} = this.state;
if (!autoPlay && prevState.autoPlay) {
this.slider.slickPause();
}
// also tried calling `this.slider.slickPlay()` when `autoPlay && !prevState.autoPlay`
}
The same as above (with componentDidUpdate
) but keeping autoplay
prop to true:
render() {
const {autoPlay} = this.state;
const settings = {
autoplaySpeed: 5000,
className: 'swiper-wrapper',
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
autoplay: true, // ***
pauseOnHover: false,
initialSlide: 1,
beforeChange: this.beforeChangeSlide,
afterChange: this.afterChangeSlide
};
...
}
In this way, it just doesn’t stop sliding.
Calling this.slider.slickPause()
instead of change state
pauseSlider() {
this.slider.slickPause();
}
Although I need to change the state also for other functionality so actually I change the state:
pauseSlider() {
this.slider.slickPause();
this.setState({foo: 'bar'});
}
Am I doing something wrong or is it a bug?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
Top Results From Across the Web
slickPause() not working · Issue #738 · kenwheeler/slick - GitHub
i solved the problem finally! It's better to pause the slick animation with slick('slickpause') on mouse over, and then you can run it...
Read more >javascript - Slick Init - slickPause undefined - Stack Overflow
When trying to pause the slider within the init listener the slick('slickPause') method doesn't work with the error.
Read more >kenwheeler/slick - Gitter
Hi, I have some problem of speed with firefox... It's extremely slow... anyone had the same problem?
Read more >Support Accessible Slick [#3196529] | Drupal.org
It doesn't seem to be doing any harm -- the settings work when I add them to the optionset (e.g., I can save...
Read more >Play/Pause buttons for Slick Slider - CodePen
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https. ... .slick('slickPause')....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I tried replicating it and I found the problem. The
autoplay
prop was available inprops
instead ofthis.props
in update mixin. Fixed that, fixed the issue. 817cd797b04e158a70ada4b2f1ea9c2dc98aab9aThe following snippet works for me:
@msalsas Finally, I’ve managed to solved issues related to autoplay/pause by managing another state in InnerSlider component. Commits like: 466e026, 877c465 and bb5de6a solve the problem. These changes are currently in dev branch and will be released soon.