A
A
Arthur Levenson2021-08-27 13:19:55
css
Arthur Levenson, 2021-08-27 13:19:55

How to interact with breakpoint in slick slider?

How to properly interact with breakpoint in slick. the slider should not be active on laptops and other large screens, but only active on mobile devices and tablets. Can you please tell me how to do this using the responsive property?

https://codepen.io/kiskiskit/pen/MWowBbW

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
depressionofoleg, 2021-08-27
@kiskiskit

With the help of responsive, this can hardly be done somehow, but you can limit the script execution depending on the screen size and resize.

function mobileOnlySlider() {
    $(document).ready(function(){
            $('.slider').slick({
                slidesToShow:3,
                slidesToScroll: 1,
                centerMode: true,
                centerPadding: '0px',
                speed: 700,
                infinite: true,
                responsive: [
                    {
                        breakpoint: 576,
                        settings: {
                            slidesToShow: 2,
                            slidesToScroll: 1
                        }
                    }
                ]
            });
    })
}

if (window.innerWidth >= 768) {
    mobileOnlySlider();
}

$(window).resize(function() {
    if(window.innerWidth >= 768) {
        if($('.slider').hasClass('slick-initialized')) {
            return;
        }
        mobileOnlySlider();
    } else {
        if($('.slider').hasClass('slick-initialized')) {
            $('.slider').slick('unslick');
        } else {
            return;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question