javascript - Fullpage.js 使用连续滚动或循环时禁用 moveSectionUp

标签 javascript jquery plugins jquery-plugins fullpage.js

刚刚开始使用 fullPage.js 并且到目前为止很喜欢它。
无论如何,当实现连续和循环效果并且您位于第一部分时,它允许最终用户向上滚动并落在最后一部分上......这在尝试向用户讲故事时是一个问题。因此我只是想禁用向上滚动,但不知道该怎么做。

我做了一些研究,发现了 moveSectionUp 并尝试禁用它,但不知道如何做。任何熟悉 fullPage.js 的人都可以帮我吗?

注意:我只希望在第一部分禁用它,其余部分可以自由地来回滚动。

提前致谢。

最佳答案

使用fullpage.js函数setAllowScrolling参数 up 如下所示:

//disabling scrolling up
$.fn.fullpage.setAllowScrolling(false, 'up');

您可以在 afterRender 回调和 afterLoad 上使用它来使用它,如下所示:

$('#fullpage').fullpage({
    sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
    continuousVertical: true,
    afterRender: function () {
        //disabling scrolling up on page load if we are in the 1st section
        if($('.fp-section.active').index('.fp-section') === 0){
            $.fn.fullpage.setAllowScrolling(false, 'up');
        }
    },
    afterLoad: function (anchorLink, index) {
        if (index !== 1) {
            //activating the scrolling up for any other section
            $.fn.fullpage.setAllowScrolling(true, 'up');
        } else {
            //disabling the scrolling up when reaching 1st section
            $.fn.fullpage.setAllowScrolling(false, 'up');
        }
    }
});

Demo online

这样访问者将无法在页面加载时向上滚动。

来自文档:

setAllowScrolling(boolean, [directions])

Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures (which is active by default).

directions: (optional parameter) Admitted values: all, up, down, left, right or a combination of them separated by commas like down, right. It defines the direction for which the scrolling will be enabled or disabled.

关于javascript - Fullpage.js 使用连续滚动或循环时禁用 moveSectionUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29046386/

相关文章:

javascript - Handlebars.js - 构建模板模板

jquery mobile 自定义加载消息直到关闭时才显示

plugins - SonarQube 在插件开发期间无法重新启动

jquery - 有关 Jquery/Masonry 的帮助,小调整

javascript - 在 jquery 中访问一个类的元素不起作用

javascript - 将多个元素放入 JavaScript 数组

javascript - 验证仅在后跟字母时才允许空格字符

php - 如何单击图像的某些部分

php - 通过 Hook 的 Woocommerce 变体

javascript - 如何使用 ReSharper 自定义 HTML 工具进行 JavaScript 测试?