thibaultlgd
thibaultlgd

Reputation: 65

add +1 class to owl-item in owl carousel

I'm trying to add a different class for each slide of my owl-carousel.

Example:

slide 1 will have for class

owl-item one

Slide 2 will have

owl-item two

etc

It needs to eb done via javascript / jquery as it for dynamic purpose.

Any help will be super !

Thank you !

Upvotes: 1

Views: 850

Answers (2)

bhansa
bhansa

Reputation: 7514

I'm assuming you have class owl-item for your carousel slide items.

var classNum = ["one", "two", "three", "four", ...]

and use:

$.each($('.owl-item'), function(i, item) {
    $(item).addClass(classNum[i]);
});

Upvotes: 0

Roland Ruul
Roland Ruul

Reputation: 1242

After owl has initialized, loop through owl items and add each of em a class.

$.each($('.owl-item'), function(i, item) {
    $(item).addClass('num-' + i);
    console.log(item);
});

Example: https://jsfiddle.net/cr29y1tc/25/

Upvotes: 1

Related Questions