Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set autoplaySpeed per slide #4273

Open
Rowdysign opened this issue Aug 15, 2023 · 1 comment
Open

Set autoplaySpeed per slide #4273

Rowdysign opened this issue Aug 15, 2023 · 1 comment

Comments

@Rowdysign
Copy link

Hello,

I use Slick Slider a lot and I am really happy with it. Thanks a lot.

I would like to set autoplaySpeed per slide. I know this is partially achievable with the afterChange event, but I can only get it working if the slide that I want to show a little bit longer is not the first slide.

So my question is: how can I set a autoplaySpeed per slide but also for the first slide?

@ZsoltBenes
Copy link

ZsoltBenes commented Oct 16, 2023

Hello,

u can use .on('afterChange', ...

example code:

const slickSliderExample = jQuery('#slickSliderExample').slick({
    autoplay: true,
    autoplaySpeed: 3000, //First slide 3000
    slidesToShow: 5,
    slidesToScroll: 1,
    dots: false,
    centerMode: true,
    focusOnSelect: true,
    variableWidth: true,
    centerPadding: '0px',
    prevArrow: "<button type='button' class='slick-prev'></button>",
    nextArrow: "<button type='button' class='slick-next'></button>",
    // the magic
    responsive: [{
        breakpoint: 1200,
        settings: {
            slidesToShow: 3,
            slidesToScroll: 1,
        }
    }, {
        breakpoint: 768,
        settings: {
            slidesToShow: 1,
            slidesToScroll: 1,
            variableWidth: true,
            centerPadding: '0px'
        }
    }]
});

// Add the afterChange event handler
slickSliderExample.on('afterChange', function (event, slick, currentSlide) {
    // Check the current slide index and change autoplaySpeed accordingly
    if (currentSlide === 2) {
        // Change autoplaySpeed for the third slide
        slickSliderExample.slick('slickSetOption', 'autoplaySpeed', 500);
    } else {
        // Other slides
        slickSliderExample.slick('slickSetOption', 'autoplaySpeed', 1500);
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants