JS scrollTo next Section onscroll

JS scrollTo next Section onscroll

我想将我网页上的滚动限制为 divs/sections 随便什么。 就像将滚动步长限制在屏幕高度一样。 如果用户滚动,无论是使用鼠标滚轮还是 mac 2 指滚动。 他应该自动滚动到下一节或上一节。 示例页面:Jenny Example FLPNY Example

我这里已经找到了一个函数,可以限制监听滚动事件(debounce)。我只是想不通如何不获得随机滚动行为。

function debounce(func, interval) {
    var lastCall = -1;
    return function () {
        clearTimeout(lastCall);
        var args = arguments;
        lastCall = setTimeout(function () {
            func.apply(this, args);
        }, interval);
    };
}

$(window).on('wheel', debounce(function (e) {
    currentScrollPosition = document.documentElement.scrollTop || document.body.scrollTop;
    var delta = e.originalEvent.deltaY;

    if (delta > 0) {
        console.log("down");

        $("html, body").animate({
            scrollTop: nextSection
        }, 500);
    }
    else {
        console.log("up");

        // this will search within the section
        $("html, body").animate({
            scrollTop: prevSection
        }, 500);

    }

不太清楚你的意思:

I just can't figure out how no to get a random scroll behaviour.

但是您 link 正在使用的网站 fullPage.js