【问题标题】:owl carousel 2.2 dots with aria-label带有 aria-label 的 owl carousel 2.2 点
【发布时间】:2017-01-24 02:09:25
【问题描述】:

我想使用包含当前显示图像的“aria-label”来增强 owl carousel 中的点。最终代码应如下所示:

<div class="owl-dot" aria-label="1><span></span></div>
<div class="owl-dot" aria-label="2"><span></span></div>
<div class="owl-dot" aria-label="3"><span></span></div>

我正在尝试使用 attr 方法达到此目的

    $('.owl-carousel .owl-dot').attr('aria-label', '+currentIndex.lenght+');

但我根本无法在 aria 标签内获得当前图像编号。 Owl carousel 有计数器或 currentIndex 吗?我该如何添加它?感谢您的帮助

【问题讨论】:

    标签: javascript jquery owl-carousel


    【解决方案1】:

    你可以遍历每个点,并给它循环的索引,如下所示:

    //Go through each carousel on the page
    $('.owl-carousel').each(function() {
        //Find each set of dots in this carousel
      $(this).find('.owl-dot').each(function(index) {
        //Add one to index so it starts from 1
        $(this).attr('aria-label', index + 1);
      });
    });
    

    【讨论】:

    • 感谢您的回答,效果很好。我现在唯一的问题是我在同一页面上确实有多个猫头鹰轮播,因此下一个画廊的索引从上一个画廊的最后一个数字继续。有没有办法将其重置为零?
    • @webmaya 试试上面编辑过的代码。数字每次应该从 1 开始
    • 您可能还想将 arial-label 添加到您的 owl-next 和 owl-prev 按钮。例如$(this).find('.owl-next').each(function(index) { //Add arial-lable to to owl-next $(this).attr('aria-label',"Next Slide"); });
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2014-05-13
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多