bootstrap 3 轮播图组件(Carousel) 获取当前显示图片的索引

官方文档

Events
Bootstrap’s carousel class exposes two events for hooking into carousel functionality.

Both events have the following additional properties:

direction : The direction in which the carousel is sliding (either “left” or “right”).
relatedTarget: The DOM element that is being slid into place as the active item.

有两个回调方法
Event TypeDescription
slide.bs.carouselThis event fires immediately when the slide instance method is invoked.
slid.bs.carouselThis event is fired when the carousel has completed its slide transition.

两个回调方法都可以使用

$(选择器).on('slide.bs.carousel', function (obj) {
        // 当前轮播索引
        var index = $(this).find('.item').index(obj.relatedTarget);
        console.log("索引:" + index);
 });

此方法针对bootstrap 3使用
网上的.getActiveIndex()方法,适用于bootsrap v3.0.2,如果出现无法获取的情况可以试试我这个方法

写在最后

本人为纯小白,所写的博客也是因为学习使用中遇到的问题进行查找资料然后解决后才编写的,其中如果有某些地方有错误,或者涉及侵权的请联系我,

QQ : 994961015
E-mail: yangxj96@126.com

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值