I
I
it_pear_yurec2018-02-21 14:52:10
css
it_pear_yurec, 2018-02-21 14:52:10

How to set opacity to the last slider block?

The slick slider has a slick-current class, you can set it to opacity 0.3 and thus every first visible slider block will become 70% transparent. How to do the same with only the last visible slider block?

<div class="slider-container">
              <div><img src="img/slider-1.png" alt=""></div>
              <div><img src="img/slider-2.png" alt=""></div>
              <div><img src="img/slider-3.png" alt=""></div>
              <div><img src="img/slider-4.png" alt=""></div>
              <div><img src="img/slider-5.png" alt=""></div>
              <div><img src="img/slider-6.png" alt=""></div>
              <div><img src="img/slider-1.png" alt=""></div>
              <div><img src="img/slider-2.png" alt=""></div>
              <div><img src="img/slider-3.png" alt=""></div>
              <div><img src="img/slider-4.png" alt=""></div>
              <div><img src="img/slider-5.png" alt=""></div>
              <div><img src="img/slider-6.png" alt=""></div>
            </div>

<script>
    $(document).ready(function(){
      $('.slider-container').slick({
        slidesToShow: 5,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
      });
    });
  </script>

slick-current styling code
.slick-current img{
    transition: all .3s;
    opacity: 0.3;
}

5a8d5df3a8985943700796.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stimulate, 2018-02-21
@it_pear_yurec

For fun, it might make you think

jQuery('.slider-container').children('.slick-slide').css('opacity', 1);
jQuery('.slider-container').children('.slick-slide.slick-active').last().css('opacity', 0.4);

Either css
.slick-slide.slick-active:last-of-type {
opacity: 0.4;
}

O
Orkhan Hasanli, 2018-02-21
@azerphoenix

Have you tried the ::last-child option? Or did it not work?
htmlbook.ru/css/last-child

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question