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.

slider does not reinitialize on resize if "unslick" is used in breakpoints

See original GitHub issue

When you configure the slider to destroy on a certain breakpoint, it is not reinitialized after resizing the browser because the “resize” event is detached when you perform “unslick”.

$('.slider').slick({
        dots: false,
        infinite: true,
        arrows: false,
        speed: 200,
        slidesToShow: 1,
        mobileFirst: true,
        responsive: [
            {
                breakpoint: 768,
                settings: 'unslick'
            }
        ]
});

Demo can be found here: https://jsfiddle.net/v5c755kp/

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

50reactions
romannikiforovcommented, Dec 7, 2018
const settings = {
     // default settings
    responsive: [
        {
            breakpoint: 900,
            settings: { slidesToShow: 3 }
        },
        {
            breakpoint: 600,
            settings: { slidesToShow: 2 }
        },
        {
            breakpoint: 420,
            settings: "unslick"
        }
    ]
};

const sl =  $('.slider').slick(settings);
      
$(window).on('resize', function() {
   if( $(window).width() > 420 &&  !sl.hasClass('slick-initialized')) {
         $('.slider').slick(settings);
    }
});
21reactions
Emiya0306commented, Nov 23, 2016

@mazzaker @simeydotme Yes, it is not a bug, but I think it is not a good choice for user to reinit it by userself. Slick should have its own instance props to log its breakpoint which causes unslick event, and next time to reinit by slick self.

If there are many slicks in one page, user should not reinit slick one by one. It causes a big trouble in my case. I think the best idea is slick can reinit by itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mobile first Carousel does not reinitialize after unslick ... - Drupal
When creating a slick carousel, that unslicks at a certain breakpoint, the carousel does not reinitialize when the breakpoint is adjusted ...
Read more >
Prevent re-init of slick slider on window resize - Stack Overflow
Instead of reinitializing you should just call .slick("resize") on that element when the window is resized. In your example this would be:.
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 >
slick - the last carousel you'll ever need - Ken Wheeler
slick is a responsive carousel jQuery plugin that supports multiple breakpoints, CSS3 transitions, touch events/swiping & much more!
Read more >
slick slider error Uncaught TypeError: Cannot read property ...
I have applied slick slider in the phtml file but is giving error ... //Now it will not throw error, even if called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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