Slick: Slick: Examples for how to reInit on orientation change

Created on 4 Mar 2017  路  2Comments  路  Source: kenwheeler/slick

I'm trying to reinitialize slick upon orientation change. My slides start centered, but when changing to landscape mode they align left. Upon refresh (at the new orientation) everything is back to normal.

I assume reInit is what I need, so I tried the following in my document ready:

// Large Product Carousel
$('.large-product-carousel').slick({
    infinite: true,
    speed: 250,
            ........ [[ truncating several other options ]] .......
    slidesToShow: 1,
    adaptiveHeight: true,
    variableWidth: true

});

$(window).resize(function(){        
    $('.large-product- carousel').slick('resize');
});

$(window).on('orientationchange', function() {      
    $('.large-product-carousel').slick('reinit');

});

I've tried with both reinit and reInit (case), but maybe I'm barking up the wrong tree.

Slick version is: Version: 1.6.0

Most helpful comment

I had a similar issue and solved it by including this in my document ready...

$(window).on('orientationchange', function() {
  $('.my-slider').slick('resize');
});

If that alone doesn't work, try adding mobileFirst: true to your settings.

All 2 comments

Might try setPosition. Providing a debugging assist is easier with a fiddle/codepen. Thanks!

I had a similar issue and solved it by including this in my document ready...

$(window).on('orientationchange', function() {
  $('.my-slider').slick('resize');
});

If that alone doesn't work, try adding mobileFirst: true to your settings.

Was this page helpful?
0 / 5 - 0 ratings