Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS滚动到下一节onscroll_Javascript_Jquery_Html_Smooth Scrolling - Fatal编程技术网

Javascript JS滚动到下一节onscroll

Javascript JS滚动到下一节onscroll,javascript,jquery,html,smooth-scrolling,Javascript,Jquery,Html,Smooth Scrolling,我想限制我的网页滚动到div/sections什么的。 比如将滚动步长限制在屏幕高度。 如果用户滚动,无论是使用鼠标滚轮还是mac 2-finger-scroll。 他应该自动滚动到下一节或上一节。 示例页面: 我已经在这里找到了一个函数,用于限制对滚动事件(去盎司)的监听。我只是想不出如何获得一个随机滚动行为 function debounce(func, interval) { var lastCall = -1; return function () { c

我想限制我的网页滚动到div/sections什么的。 比如将滚动步长限制在屏幕高度。 如果用户滚动,无论是使用鼠标滚轮还是mac 2-finger-scroll。 他应该自动滚动到下一节或上一节。 示例页面:

我已经在这里找到了一个函数,用于限制对滚动事件(去盎司)的监听。我只是想不出如何获得一个随机滚动行为

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);

    }

不太清楚你说的是什么意思:

我只是想不出如何获得一个随机滚动行为

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);

    }

但是你链接的网站正在被利用

这正是我想要的。我试图自己编写这种效果的代码,有时会导致随机的上下滚动,我不明白为什么会这样。