【问题标题】:Detect that Bootstrap carousel ended检测 Bootstrap 轮播结束
【发布时间】:2022-01-11 23:32:19
【问题描述】:

我想知道是否有任何方法可以检测 Bootstrap 轮播何时结束运行,因为我需要在轮播到达最后一个元素时执行一个函数。

我在这里将问题应用于评论,以便以更好的格式查看它:

const carousel = document.getElementById("carouselContainer");

carousel.addEventListener("slid.bs.carousel", function (e) {
    if (e.direction === "right" && e.to === elements.length - 1) {
      // Take an action
    }
  });

【问题讨论】:

    标签: javascript html css bootstrap-carousel


    【解决方案1】:

    是的,检查documentation:你应该根据direction比较fromto

    
    if (direction == 'left' && to == 0) {
        startReached();
    }
    
    if (direction == 'right' && to == elements.length - 1) {
        endReached();
    }
    

    【讨论】:

    • 您好 Justinas,感谢您的回答。你的意思是做这样的事情? const carousel = document.getElementById("container"); carousel.addEventListener("slid.bs.carousel", function (e) { if (e.direction === "right" && e.to === elements.length - 1) { // // 采取行动 } });
    • 是的,像这样
    猜你喜欢
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多