Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize Slick Slider when page loads completely

I'm using Slick Slider with content in each slide (text and images):

<div id="misresenas">
   <div class="resena">
      <!-- my content -->
   </div>
   <div class="resena">
      <!-- my content -->
   </div>
   <div class="resena">
      <!-- my content -->
   </div>
</div>

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
      $("#misresenas").slick({
        arrows:false,
        autoplay:true
      });
  });
</script>

The problem is when I load page, at the beginning Slick Slider looks like this with one slide above the other until it finishes load page and then it starts working:

enter image description here

I tried to put these lines on CSS but It doesn't work, the slider is completely hidden:

#misresenas{display:none;}
#misresenas .slick-initialized{display:block;}

How can I fix it?

like image 748
NekoLopez Avatar asked Mar 11 '26 17:03

NekoLopez


2 Answers

Here you go. Replace $(document).ready() with $(window).load() function.

<script type="text/javascript">
  $(window).on('load', function() {
     $("#misresenas").slick({
       arrows:false,
       autoplay:true
     });
  });
</script>
like image 158
Rajan Benipuri Avatar answered Mar 14 '26 09:03

Rajan Benipuri


That's the correct code

#misresenas{display:none;}
#misresenas.slick-initialized{display:block;}
like image 40
SpaceDogCS Avatar answered Mar 14 '26 08:03

SpaceDogCS