Javascript 在fullpage.js上获取当前幻灯片

Javascript 在fullpage.js上获取当前幻灯片,javascript,jquery,fullpage.js,Javascript,Jquery,Fullpage.js,我是一个快乐的Fullpage.js用户 我只想添加一个类(.num),显示当前幻灯片数量/幻灯片总数 我使用的这个功能很好,问题是它不会在幻灯片更改时更新 $('.section').each(function(){ var section = $(this), sectionSlides = section.find('.slide'), totalItems = sectionSlides.length, currentIndex = sectionSlid

我是一个快乐的Fullpage.js用户
我只想添加一个类(.num),显示当前幻灯片数量/幻灯片总数

我使用的这个功能很好,问题是它不会在幻灯片更改时更新

$('.section').each(function(){
    var section = $(this),
    sectionSlides = section.find('.slide'),
    totalItems = sectionSlides.length,
    currentIndex = sectionSlides.filter('.active').index() + 2,
    numContainer = section.find('.num');

numContainer.html(currentIndex + ' / ' + totalItems);
});
三种方式:

  • 使用回调,例如
  • 使用
  • 只是做一些类似于
    $('.fp section.active').find('.fp slide.active')

我相信这段代码可以解决我的问题,也许我只需要更改警报

$('#fullpage').fullpage({
    onSlideLeave: function( anchorLink, index, slideIndex, direction, nextSlideIndex){
        var leavingSlide = $(this);

        //leaving the first slide of the 2nd Section to the right
        if(index == 2 && slideIndex == 0 && direction == 'right'){
            alert("Leaving the fist slide!!");
        }

        //leaving the 3rd slide of the 2nd Section to the left
        if(index == 2 && slideIndex == 2 && direction == 'left'){
            alert("Going to slide 2! ");
        }
    }
});

您如何检查当前幻灯片是否已更改?嗯,我不知道,我认为已更改。活动状态已足够。我认为您需要确定活动幻灯片更改时触发的事件。是当你点击某个按钮时,比如“下一步”还是“上一步”?之后,当新的活动幻灯片显示出来时,您需要将一些代码放入该事件处理程序。我可以单击右/左箭头转到下一张/上一张幻灯片,但也可以使用键盘上的箭头。我可以问你一个如何触发该事件的提示吗?当然可以,但是你也可以发布包含这些按钮功能的html和javascript。谢谢你的提示onSlideLeave的问题是我无法设置某人离开的方向。在currentIndex中,它可以是左或右so+1或-1。请检查回调中的参数
direction