阻止从部分滚动,但允许在Fullpage.js中进行锚点导航

问题描述 投票:0回答:1

我的第一个fullpage.js部分是可滚动的(scrollOverflow: true),我不希望在到达第一部分的底部时跳转到第二部分。

因此,我设置了以下回调:

onLeave: function(origin, destination, direction) {
    if (origin.index === 0) {
        return false;
    }
}

问题是,这也会阻止常规锚链接(例如<a href="#section2">)工作:导航也被回调阻止。

这很烦人,因为我的第一页有链接到其他部分。

有没有办法防止onLeave只是当它是由于滚动,但仍然允许锚导航?

回调参数似乎没有办法区分滚动和锚点击。

fullpage.js
1个回答
0
投票

有没有办法防止onLeave只有当它是由于滚动,但仍然允许锚导航?

当然!使用scrollOverflow到达该部分时,可以使用fullpage_api.setAllowScrolling(false)方法。

然后在任何其他部分将其设置为true:

new fullpage('#fullpage', {
    sectionsColor: ['yellow', 'green', 'purple', 'orange'],
    navigation: true,

    onLeave: function(origin, destination, direction) {
        //assuming section 2 is the one with scrollOverflow
        fullpage_api.setAllowScrolling(destination.index !== 1);
    }
});

在线复制:https://jsfiddle.net/alvarotrigo/zx05cfr9/1/

© www.soinside.com 2019 - 2024. All rights reserved.