question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unslick responsively

See original GitHub issue

I have a slider with four elements, at a screen size greater than a certain breakpoint, I’d like to disable slick and use CSS to render them as a 2x2 block grid. Is there a way to do this, or can it be added so you can have something like

$('.responsive').slick({
  dots: true,
  infinite: false,
  speed: 300,
  slidesToShow: 4,
  slidesToScroll: 4,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        unslick: true
      }
    },
    {
      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 2
      }
    },
    {
      breakpoint: 480,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }
  ]
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:68 (7 by maintainers)

github_iconTop GitHub Comments

114reactions
jmarcelicommented, Jan 4, 2016

For me overwriting core file as @ashussen supposed was not an option. The only working solution is writing custom “reslicking” function:

  $slick_slider = $('.slider');
  settings = {
    // some settings
  }
  $slick_slider.slick(settings);

  // reslick only if it's not slick()
  $(window).on('resize', function() {
    if ($(window).width() < 768) {
      if ($slick_slider.hasClass('slick-initialized')) {
        $slick_slider.slick('unslick');
      }
      return
    }

    if (!$slick_slider.hasClass('slick-initialized')) {
      return $slick_slider.slick(settings);
    }
  });
68reactions
cibgraphicscommented, Sep 17, 2015

I disagree @kenwheeler. A usecase could be that a slider could be working on an iPad portrait and the user turns ipad to landscape, and then back to portrait. If the breakpoint was between those two sizes the slider would no longer be functioning when it should be.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to unslick/hide a Slick slider for desktops but slick ...
Much cleaner solution than the currently accepted answer: Add the mobileFirst: true, option: $('.slider').slick({ slidesToShow: 5, ...
Read more >
how to resize slick and unslick - CodePen
Resize the browser to see it working. An example showing how to start and stop slick responsible, like the "unslick" property but re-slicking...
Read more >
(Truly) Responsive Slick Slider Code - Frontend.services |
It does but with one huge issue – once element is turned from Slick to no Slick it can never get back into...
Read more >
slickslide pc:unslick after mobile:slick - 네이버 블로그
('.slider').slick({ slidesToShow: 5, slidesToScroll: 1, autoplay: false, autoplaySpeed: 2000, responsive: [ { breakpoint: 9999, ...
Read more >
slick slider unslick responsive Code Example - Code Grepper
('.your-slider').slick('unslick');
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found