如何获得轮播的总数和当前幻灯片数量 [英] How to Get total and Current Slide Number of Carousel

查看:146
本文介绍了如何获得轮播的总数和当前幻灯片数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否让我知道如何在自举程序中获得旋转式载玻片的总数和当前数量,如下图所示?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆