A
A
arctic072019-12-20 23:00:55
JavaScript
arctic07, 2019-12-20 23:00:55

Slider Slider. How to make adding a class at the time of moving the slide?

By pressing Right. Until the moment of flipping, a class is added to slide No. 2. And he moves to position #1 of the slide. In the opposite direction as well. The rest of the slides should remove this class.
5dfd27625f1bb399368521.png
5dfd2774ba404371450331.png
That is, when slide No. 1, which is hidden on the left, is moved to the central position, class is removed for slide No. 2 and slide No. 1 is added and it arrives at the central position already with this class.

I made a color change to make it easier. In real life, the picture will increase and blocks will appear.
https://codepen.io/arcticmonkey07/pen/KKwWJMR
I managed to make adding only one way...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-12-21
@arctic07

.on('beforeChange', function(e, { slideCount: c }, curr, next) {
  const selector = shift => `[data-slick-index="${next + shift * c}"] .slide`;

  $('.slide.color', this).removeClass('color');
  $([ 0, 1, -1 ].map(selector).join(', '), this).addClass('color');
})

S
sashabeep, 2019-12-20
@sashabeep

I didn’t understand why the class of the active slide didn’t fit?
Or should the class be assigned only at the moment of animation, and then removed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question