K
K
kachurinets2018-08-23 12:30:49
css
kachurinets, 2018-08-23 12:30:49

How to get first and last visible slide?

https://codepen.io/anon/pen/qMdQvW
There is such a slider. How to reach the first and last slide that is visible? Does the slick have a similar property? You need to put transparency on the first and last slide.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Crimsons, 2018-08-23
@crimsons

The whole point is that slick has built-in events with which we can call a function every time this event occurs. The code needs to be added after the initialization of your slider.

//Добавляем всем элементам прозрачность
$('.slick-slide').addClass('slick-slider-opacity');
//Убираем прозрачность у центральных элементов
$('.slick-slide.slick-active').eq(1).removeClass('slick-slider-opacity');
$('.slick-slide.slick-active').eq(2).removeClass('slick-slider-opacity'); 
//Вешаем обработчик на событие слайдера
$(".rio-promos").on("afterChange", function() {
  //Добавляем прозрачность всем элементам, обнуляя её у нужных
  $('.slick-slide').addClass('slick-slider-opacity');
  $('.slick-slide.slick-active').eq(1).removeClass('slick-slider-opacity');
  $('.slick-slide.slick-active').eq(2).removeClass('slick-slider-opacity'); 
});

CSS code
.slick-slide {
  transition: 0.5s opacity linear;
}
.slick-slider-opacity {
  opacity: 0.5;
}

Such code will work only for 4 visible elements. I'm sure under other conditions you will be able to figure out how you can change / modify this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question