E
E
Evtera2020-05-09 10:59:21
JavaScript
Evtera, 2020-05-09 10:59:21

How to implement class change by Jquery array index?

Hello. There is a slick slider. I want to make this function, when activated, change the class of another block according to the index of the called function.

That is, if the index is 1, then the block has a new class class_1, if the index is 2, then it changes to class_2.

or as the second option, so that it is not the class that changes, but the background property: URL(img-$`{1}.png).

With jQuery I'm really bad :D.

$('.first-screen__slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
console.log(nextSlide);

$('.first-screen').toggleClass(`first-screen__sliderContent_ ${nextSlide}`)
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n1ksON, 2020-05-09
@n1ksON

If there are few slides, then you can use the switch construct and the toggleClass method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question