在fullpage.js中重新激活自动滚动

Reactivate automatic scroll in fullpage.js

本文关键字:激活 滚动 js fullpage 新激活      更新时间:2023-09-26

我正在寻求一些帮助!

我正在使用Alvaro Trigo的Fullpage.js开发Wordpress网站。

在主页上,我让每个部分每5000毫秒自动滚动一次。

如果用户决定使用鼠标导航每个部分,则当前会覆盖此功能。

如果用户处于非活动状态(即未手动滚动)达5000ms,则客户端已请求重新激活自动滚动。

这是正在进行的工作。

提前谢谢你——任何帮助都将不胜感激!如果你需要更多信息,请告诉我。

在线示例

试试这个:

var myIntervalId;
var auto = true;
$('#fullpage').fullpage({
    sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
    continuousVertical: true,
    afterLoad: function (anchorLink, index){
        //for any section
        if(typeof myIntervalId === 'undefined' || !auto){
          clearInterval(myIntervalId);
          myIntervalId = setInterval(function() {
              $.fn.fullpage.moveSectionDown();
          }, 1000);
        }
    }
});


addMouseWheelHandler();
function MouseWheelHandler() {
    clearInterval(myIntervalId);
    auto = false;
}
function addMouseWheelHandler() {
    if (document.addEventListener) {
        document.addEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
        document.addEventListener('wheel', MouseWheelHandler, false); //Firefox
    } else {
        document.attachEvent('onmousewheel', MouseWheelHandler); //IE 6/7/8
    }
}