从BxSlider获取当前幻灯片编号

时间:2014-08-25 06:08:42

标签: jquery

我正在使用jQuery bxslider。

当我点击下一步时,我希望获得currentlidenumber,这是我的代码

function slider() {
 $('.recent_articles').bxSlider({
        slideWidth: 223,
        minSlides: 2,
        maxSlides: 8,
        moveSlides: 1,
        slideMargin: 18,
           infiniteLoop: false,
           pager:false,

       });
}


$(document).on('click','.bx-next', function() {
 var total = slider.getCurrentSlide();
 alert(total);
});

slider();

现在,当我点击时,我收到此错误:

  

TypeError:slider.getCurrentSlide不是函数

有人告诉我该怎么做

由于

2 个答案:

答案 0 :(得分:3)

以下是代码:

var mySider = $('.recent_articles').bxSlider({
                   slideWidth: 223,
                   minSlides: 2,
                   maxSlides: 8,
                   moveSlides: 1,

                   ------
                   ------
               });

并且,将getCurrentSlide()调用为:

$(document).on('click','.bx-next', function(){
    var total = mySider.getCurrentSlide();
    alert(total);
});

答案 1 :(得分:0)

$('.stepslider').bxSlider({
minSlides: 1,
maxSlides: 1,
moveSlides: 1,
slideWidth: 1280,
slideMargin: 5,
infiniteLoop: false,
auto: false,
hideControlOnEnd: true,
pager: false,
onSlideBefore: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
var gosteps = currentSlideHtmlObject+1; //get current slide index you can add class this is working in mobile touch also
$(".steps-count span").text(gosteps);
console.log(currentSlideHtmlObject+1); //get current slide
}
});

使用currentSlideHtmlObject元素可以在获取幻灯片之前获取当前幻灯片,而必须将currentSlideHtmlObject + 1更新为当前幻灯片。