2015-12-01 101 views
2

我正在寻找一些帮助!重新激活fullpage.js中的自动滚动功能

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

在主页上,我有每个部分每5000ms自动滚动一次。

如果用户决定使用鼠标浏览每个部分,则此功能目前被覆盖。

如果用户在5000ms内不活动(即不是手动滚动),客户端请求重新激活自动滚动。

Here is the work in progress

在此先感谢您 - 任何帮助将不胜感激!如果您需要更多信息,请告诉我。

回答

0

Example online

试试这个:

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 
    } 
} 
+0

嗨阿尔瓦罗 - 谢谢你回来这么快。我可能没有正确解释这个... 我需要自动滚动重新激活后,用户用鼠标停止它,然后5秒钟无效。在JSFiddle中,鼠标滚轮会停止自动滚动,但不会重新激活。 提前致谢,并对错误沟通感到抱歉。 埃文。 – Evan

+0

@Evan这个例子在用户停止时重新激活滚动。再次审查。你可以测试它滚动。它会在1秒后再次激活。 (只是把它改为5你的情况) – Alvaro

+0

对不起,它不适用于我:(我已经在Safari,Firefox和Chrome中试过了,我能够以某种方式给你看一个屏幕截图吗? – Evan