G
G
glem13372018-08-31 15:20:40
JavaScript
glem1337, 2018-08-31 15:20:40

How to enable the slick slider at a certain resolution, and disable it when the window is resized?

I did it in this way, I don’t like it, because. errors are thrown into the console
kp2au0

var clientWidth = document.body.clientWidth;

$('.tales__slider').slick({
    arrows: false,
    dots: true,
    infinite: true,
    slidesToScroll: 1,
    variableWidth: true
  });

function resizeTaleSlider(clientWidth) {
    if (clientWidth < 992) {
      $('.tales__slider').slick({
        arrows: false,
        dots: true,
        infinite: true,
        slidesToScroll: 1,
        variableWidth: true
      });
    } else {
      $('.tales__slider').slick("unslick");
    }
  }

  resizeTaleSlider(clientWidth);

  $(window).resize(function() {
    let clientWidth = document.body.clientWidth;
    resizeTaleSlider(clientWidth);
  });


In general, this method seems to me a crutch, is there a "native" way to solve this problem? I didn't find anything in the official docs about this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Vasiliev, 2018-08-31
@glem1337

See option responsive.
Try like this:

$('.tales__slider').slick({
  arrows: false,
  dots: true,
  infinite: true,
  slidesToScroll: 1,
  variableWidth: true,
  mobileFirst: true,
  responsive: [{
    breakpoint: 992,
    settings: 'unslick'
  }]
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question