如何获得轮播的总数和当前幻灯片数量 [英] How to Get total and Current Slide Number of Carousel
问题描述
能否让我知道如何在自举程序中获得旋转式载玻片的总数和当前数量,如下图所示?
Can you please let me know how I can get the total and current number of the carousel slides in bootstrap like the image below?
我有一个标准的Bootstrap传送带和一个带有.num
类的<div>
来显示总数和当前数字,我使用此代码来检索数字,但没有通过
I have an standard Bootstrap carousel and a <div>
with the .num
class to display the total and current number and I used this code to retrieve the numbers but it didn't go through
$('.num').html(){
$('#myCarousel').carousel({number})
}
谢谢
更新:
请在此jsfiddle中找到一个示例 LINK
Please find a sample at this jsfiddle LINK
推荐答案
每个slide
都有一个.item
类,您可以获得这样的幻灯片总数
Each slide
has a .item
class to it, you can get the total number of slides like this
var totalItems = $('.item').length;
活动slide
具有一个名为active
的类,您可以像这样获取active slide
的索引
Active slide
has a class named as active
, you can get the index of active slide
like this
var currentIndex = $('div.active').index() + 1;
您可以通过绑定这样的引导轮播slid
事件来更新这些值
You can update these values by binding the bootstrap carousel slid
event like this
$('#myCarousel').bind('slid', function() {
currentIndex = $('div.active').index() + 1;
$('.num').html(''+currentIndex+'/'+totalItems+'');
});
这篇关于如何获得轮播的总数和当前幻灯片数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!