A
A
Andrey2018-02-12 14:11:02
JavaScript
Andrey, 2018-02-12 14:11:02

How to disable Slick slider?

You need to disable the slider at a screen size of 768 and above, and below 768 enable it.
Here is the code I did:
$(function() {
$('.s-players').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
slidesToScroll: 1,
responsive: [
{
breakpoint : 768,
settings: "unslick"
}
]
});
});
But here it turns out the opposite, up to 768 it works, but after that it doesn’t. Tell me how to do it right.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
profesor08, 2018-02-12
@Fotoz

Here it works. But you need to understand that this does not work the way you want. And if unslick worked, then you need to reload the page so that it starts working again with a larger window size.

$(".single-item").slick({
  dots: true,
  infinite: true,
  speed: 300,
  slidesToShow: 3,
  slidesToScroll: 1,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 3,
        infinite: true,
        dots: true
      }
    },
    {
      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 2
      }
    },
    {
      breakpoint: 480,
      settings: "unslick"
    }
  ]
});

But it looks good, but the implementation could be better. Therefore, instead of breakpoints in the config, it is better to control the process yourself.
window.addEventListener("resize", function() {
  if (window.innerWidth <= 768) {
    $('.your-slider').slick('unslick');
    sliderIsLive = false;
  }
  else {
    if (sliderIsLive) {
      $('.your-slider').slick();
      sliderIsLive = true;
    }
  }
});

S
Svet280, 2021-02-22
@Svet280

$('.slider').slick({
     mobileFirst: true,
     responsive: [
        {
           breakpoint: 767,
           settings: "unslick"
        }
     ]
  });

A
Alexey Semenov, 2018-02-12
@immortal4651

And if you try to disable it by 0, and enable it by 769 (I have no way to check.):

$(function() {

$('.s-players').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 1,
slidesToScroll: 1,
responsive: [
{
breakpoint: 0,
settings: "unslick"
},
{
  breakpoint: 769,
  setting:{
    speed: 300,
    slidesToShow: 1,
    slidesToScroll: 1,

}
}
]
});
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question