Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable and disable Slick Slider on certain break points

I'm trying to enable Slick Slider (slick.js) to initiate only over 520px wide. Anything below that and the slides just stack (i.e. no slick). Is it possible so that it can work without refreshing the page?

I've done this, which works when dragging the browser (narrow) below 500px, but when I move it over 500px it doesn't re-initiate without refreshing the page...

$('.slick').slick({
    autoplay: true,
    autoplaySpeed: 4000,
    delay: 5000,
    speed: 700,
    responsive: [
        {
            breakpoint: 500,
            settings: "unslick"
        }
    ]
});

Is there a way around this?

I'm using https://github.com/kenwheeler/slick

like image 944
Jack Barham Avatar asked Aug 19 '15 14:08

Jack Barham


People also ask

How do I turn off autoplay on slick slider?

click(function() { $('. autoplay'). slick('autoplay', false); }); });

What is slider breakpoint?

Breakpoints are the pixel values where Smart Slider changes to show a different layout. For example, you can use breakpoints to make the slider switch to tablet view below 1199px screen width. Breakpoints in Smart Slider based on both the width and height of the browser where the slider displays.


1 Answers

You can try to reconstruct it when the window is resized above 500. This seems to work in my demo.

JSFiddle Demo

function slickify(){
    $('.slick').slick({
        autoplay: true,
        autoplaySpeed: 4000,
        delay: 5000,
        speed: 700,
        responsive: [
            {
                breakpoint: 500,
                settings: "unslick"
            }
        ]
    });
}

slickify();
$(window).resize(function(){
    var $windowWidth = $(window).width();
    if ($windowWidth > 500) {
        slickify();   
    }
});
like image 85
Steve Avatar answered Oct 15 '22 15:10

Steve