Javascript – Slick Carousel css fade transition doesn’t work on first slider

csshtmljavascriptjquery

I have a standard slick carousel slider. I made it so each div fades in and out when it slides. My issue is, after going through all the divs, when it restarts, the first div does not fade in, but rather appears suddenly and delayed.

JSFiddle: https://jsfiddle.net/BradMitchell/3gLtjL7h/

HTML

<div class="single-item">
  <div class="box"><h2>1</h2></div>
  <div class="box"><h2>2</h2></div>
  <div class="box"><h2>3</h2></div>
</div>

CSS

.slick-slide {
        opacity:0;
        transition:opacity 0.3s ease-out;
    }

.slick-active {
        opacity:1!important;
        transition:opacity 0.3s ease-in;
    }

Best Answer

Here is workaround: link. The only change is css

.slick-cloned {
  opacity: 0.3;
}

This solution is really just faking and relies on imperfection of human eye to not notice tiny fading gradients' changes at high speeds.

You may have to play around with values. The faster transition the smaller opacity value you want to have. I tested and figured at transition speed of 2s you want to have opacity set to 0.1. See for yourself.

$('.single-item').slick();
.single-item {
  width:200px;
}

.box {
  height:200px;
  width:200px!important;
  text-align:center;
  background-color:rgb(50,50,50);
  color:white;
}

.slick-slide {
		opacity:0;
		transition:opacity 1s ease-out;
	}
  
.slick-active {
		opacity:1!important;
		transition:opacity 1s ease-in;
	}
  
.slick-cloned {
  opacity: 0.3;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css" rel="stylesheet"/>


<div class="single-item">
  <div class="box"><h2>1</h2></div>
  <div class="box"><h2>2</h2></div>
  <div class="box"><h2>3</h2></div>
</div>

Related Topic