Stop autoplay after clicking on dots in slick.js
Asked Answered
B

3

8

So, this is code I use for slider:

$('.autoplay').slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    autoplay: true,
    autoplaySpeed: 2000,
    dots: true
});

And I want that after user clicks on any dot, it will disable autoplay. Then I tried this:

$('.autoplay').on('init', function() {
    $('.slick-dots').click(function() {
        $('.autoplay').slick('autoplay', false);
    });
});

But no help. Here is DEMO from jsFiddle. Is this possible with slick.js?

Broccoli answered 7/6, 2016 at 9:27 Comment(0)
J
15

Try this

$('.autoplay').slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    autoplay: true,
    autoplaySpeed: 1000,
    dots: true
});

$('.slick-dots').on('click', function() {
    $('.autoplay').slick('slickPause');
});
Jansenism answered 7/6, 2016 at 9:42 Comment(1)
Hell yeah :) Thanks, that's it.Heilbronn
S
3

From one of the issues in the github-forum, I saw that you have to attach init event before initializing with slick.

$('.autoplay').on('init', function(slick) {
    $('.slick-dots').on('click',function() {
        $('.autoplay').slick('slickPause');
    });
}).slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    dots: true,
    autoplay: true,
    autoplaySpeed: 2000,
})

DEMO HERE

Sympathetic answered 7/6, 2016 at 9:51 Comment(0)
F
1

You can use

$('.slick').slick('slickPause');

to pause. You can play it again with

$('.slick').slick('slickPlay');
Fantast answered 26/10, 2021 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.