fullpage.js在节之间添加了2个自动滚动事件

fullpage.js adding 2 autoscroll events between section

本文关键字:2个 滚动 事件 添加 js 之间 fullpage      更新时间:2023-09-26

是否可以在部分滚动到下一部分之前添加自动滚动事件?比方说,在滚动到第2节之后,用户必须滚动两次,这将激活两个单独的动画,然后再滚动到第3节。我应该禁用自动滚动吗?我试过用这个

onLeave: function(index, nextIndex, direction){
                if(index == 2 && direction =='down'){
                    function act2s(){
                        $('.sc1').removeClass('opno').delay(1000).promise().done(function(){
                            $('.sc2').removeClass('opno').delay(500).promise().done(function(){
                                $('.vg_act2-inner').addClass('vertical_grid_active');
                                $('.hg_act2-anti_inner').addClass('horizontal_grid_active');
                                $('.hg_act2-anti_out-inner').addClass('hg_act2-anti_out-inner_active');
                                $('.hg_act2-inner').addClass('hg_act2-inner_active').delay(500).promise().done(function(){
                                    $('.red2').addClass('red_active');
                                });
                            });
                        });
                    }
                    setTimeout(act2s, 2000);
                    return false;
                }
            },

然而,有一个奇怪的原因,动画在第一个sc1移除类之后就停止了。有没有办法捕捉两个滚动事件来激活动画,然后再次返回true,以便该部分可以继续滑动?

查看文档

在滚动发生之前取消滚动

您可以通过在onLeave回调上返回false来取消滚动:

  $('#fullpage').fullpage({
        onLeave: function(index, nextIndex, direction){
            //it won't scroll if the destination is the 3rd section
            if(nextIndex == 3){
                return false;
            }
        }
    });