bootstrap中获取当前的图片索引值

来源:互联网 发布:淘宝类目在哪里设置 编辑:程序博客网 时间:2024/06/03 12:58

刚刚学习使用bootstrap的轮播效果,想通过对当前图片的判断展示不同的carousel-caption.

$("#secondDiv").carousel("cycle");var pastItem;$("#secondDiv").on("slide.bs.carousel",function(){varpastItemob=$(this).find(".item.active");pastItem=pastItemob.index();})$("#secondDiv").on("slid.bs.carousel",function(){ var showItem=$(this).find(".item.active");$(".carousel-caption")[pastItem].style.display="none";showItem.children(".carousel-caption").fadeIn(300);})
我的轮播图的容器命名是id=secondDiv,通过对轮播图的两个事件触发改变,用pastItem来获取已经展示完成的图片的索引,然后在下一张图片将要展示的时候,同事把已经展示完成的图片display:none。

有一点就是find中.item 和.active之间不能有空格,否则就获取不到当前的元素。对应jQuery版本为3.2.1

效果完美实现