【问题标题】:Retrieve owl-carousel item index when clicking on div inside this carousel item单击此轮播项目内的 div 时检索 owl-carousel 项目索引
【发布时间】:2019-12-23 05:50:45
【问题描述】:

我有一个带有动态添加项目的猫头鹰轮播,每个项目都包含一个删除按钮。

当我点击这个按钮时,我想获取父轮播项目的itemindex来调用我的轮播的remove事件。

如何检索此索引?

我真的需要按钮的父项的项目索引,因为一次显示许多轮播项目,我不想要“当前项目索引”

我尝试了什么:

//retrieve parent item of clicked button
var owlitem = $(this).parents('.owl-item');

var index = $('.owl-carousel').data('owl.carousel')._items.indexOf(owlitem);

但它返回 -1

【问题讨论】:

    标签: javascript jquery owl-carousel


    【解决方案1】:

    我认为你可以使用 changed 事件来跟踪当前索引:

    // Listen to owl events:
    owl.on('changed.owl.carousel', function(event) {
        var currentItem = event.item.index;
        window.location.hash = currentItem + 1;
    })
    

    【讨论】:

    • 谢谢,但正如我所说,我不想要当前索引,因为一次显示许多项目并且用户可以关闭其中任何一个,而不仅仅是当前项目
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2015-04-11
    相关资源
    最近更新 更多