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

Pressing Right. Until the turn adds a class to the slide 2. And it goes to position # 1 slide. In the opposite direction as well. Other slides have to get out of this class.
5dfd27625f1bb399368521.png
5dfd2774ba404371450331.png
That is, when you move the slide 1, which is hidden on the left in Central position, slide No. 2 deleted the class and slide No. 1 is added and it arrives at a Central position already in this category.

I did change the color to simplify. In real life will increase the picture to see the blocks.
https://codepen.io/arcticmonkey07/pen/KKwWJMR
I was able to add only one way...
April 3rd 20 at 18:52
2 answers
April 3rd 20 at 18:54
Solution
.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');
})
Thank you!!! graminacea!! - devyn_Heaney commented on April 3rd 20 at 18:57
I can only understand how it works, if not difficult, can you describe? - devyn_Heaney commented on April 3rd 20 at 19:00
@devyn_Heaney, to simulate an infinite scroll adds a slick copy of the slides - the first in the end in the beginning. For this reason, it is necessary to add not only slide to scroll, but to its copy - otherwise the user will not see the effects caused by adding a class during the transition from end to beginning or from beginning to end. How, knowing the index of the slide to find the index of its copy? - add/subtract the number of slides. - Alek54 commented on April 3rd 20 at 19:03
April 3rd 20 at 18:56
I do not understand what does not fit the class active slide?
Or the class should be assigned only at the time of the animation, and then withdraw?
woBTmXd.png
the problem is that when clicking on Previous slide #1 added class, and he came to the place of slide # 2
at the same time the slide 2 peremeschyaetsya right and he deleted the class . Get this:
2zS6rYj.png

active slide 2 there and with them, logic doesn't work. - devyn_Heaney commented on April 3rd 20 at 18:59
@devyn_Heaney, on this page, in the second example from the top of the active slide as much as three - Assunta.Thi commented on April 3rd 20 at 19:02

Find more questions by tags jQuerySlick