简体   繁体   English

为 owl carousel 中的 owl-item 添加 +1 类

[英]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幻灯片 1 将用于课堂

owl-item one

Slide 2 will have幻灯片 2 将有

owl-item two

etc等等

It needs to eb done via javascript / jquery as it for dynamic purpose.它需要通过 javascript / jquery 来完成,因为它是出于动态目的。

Any help will be super !任何帮助都将是超级的!

Thank you !谢谢 !

After owl has initialized, loop through owl items and add each of em a class.在 owl 初始化之后,循环遍历 owl 项目并将每个 em 添加一个类。

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

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

I'm assuming you have class owl-item for your carousel slide items.我假设您的轮播幻灯片项目有类owl-item

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

and use:并使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM