Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick slider not being responsive when resizing the window

I have created a image slider in WordPress using slick slider. I am using center mode I want one image centered with one on each side slightly showing. But I am having a few problems. Firstly when I resize the window slick slider doesn't calculate the new image widths until I interact with the slider, this is problem is not present in the demo. Secondly the images on each side aren't showing like they should.

https://codepen.io/Reece_Dev/pen/xLQwEb

$('.carousel').slick({
  centerMode: true,
  centerPadding: '0px',
  slidesToShow: 1,
});
#container{
  width: 100%;
}

.slick-slide img{
    width: 80%;
    height: auto;
    max-width: 2000px;
}
<script src="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.min.js"></script>
<link href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="container">
  <div class="carousel">
    <div><img src="http://fyberproperty.co.uk/wp-content/uploads/2017/04/stairs_one2200.png"></div>
    <div><img src="http://fyberproperty.co.uk/wp-content/uploads/2017/04/stairs_two2200.png"></div>
    <div><img src="http://fyberproperty.co.uk/wp-content/uploads/2017/04/stairs_one2200.png"></div>
  </div>
</div>
like image 421
Reece Avatar asked Aug 29 '17 12:08

Reece


1 Answers

Answer from slick creator, Ken Wheeler, himself:

$('.slider-class').slick('setPosition');

https://stackoverflow.com/a/32107099/3396866

like image 149
Dilan Avatar answered Nov 15 '22 20:11

Dilan