如何使用 fullpage.js 设置不同的 setInterval 速度
How to set different setInterval speed using fullpage.js
我有以下不同的部分:
<div id="fullpage">
<div class="section" id="first" data-sec="1000">First</div>
<div class="section" id="second" data-sec="3000">Second</div>
<div class="section" id="third" data-sec="6000">Third</div>
<div class="section" id="fourth" data-sec="1000">Fourth</div>
我当前的 fullpage.js 代码如下:
var curDelay = 1000;
$("#fullpage").fullpage({
loopBottom: true,
afterLoad: function(anchorLink, index) {
var curDelay = $(this).data('sec');
console.log(curDelay);
},
});
setInterval(goSection,curDelay);
function goSection() {
$.fn.fullpage.moveSectionDown();
}
我想根据每个数据秒值设置不同的 setInterval 速度。目前它只是使用默认值。
您必须清除间隔并在 afterLoad
中重新创建它。
试试这个:
var curDelay = 1000;
var intervalID;
$("#fullpage").fullpage({
loopBottom: true,
afterLoad: function(anchorLink, index) {
var curDelay = $(this).data('sec');
clearInterval(intervalID); // <-- here
intervalID = setInterval(goSection, curDelay); // <-- here
},
afterRender: function(){
intervalID = setInterval(goSection, curDelay); // <-- here
}
});
function goSection() {
$.fn.fullpage.moveSectionDown();
}
我有以下不同的部分:
<div id="fullpage">
<div class="section" id="first" data-sec="1000">First</div>
<div class="section" id="second" data-sec="3000">Second</div>
<div class="section" id="third" data-sec="6000">Third</div>
<div class="section" id="fourth" data-sec="1000">Fourth</div>
我当前的 fullpage.js 代码如下:
var curDelay = 1000;
$("#fullpage").fullpage({
loopBottom: true,
afterLoad: function(anchorLink, index) {
var curDelay = $(this).data('sec');
console.log(curDelay);
},
});
setInterval(goSection,curDelay);
function goSection() {
$.fn.fullpage.moveSectionDown();
}
我想根据每个数据秒值设置不同的 setInterval 速度。目前它只是使用默认值。
您必须清除间隔并在 afterLoad
中重新创建它。
试试这个:
var curDelay = 1000;
var intervalID;
$("#fullpage").fullpage({
loopBottom: true,
afterLoad: function(anchorLink, index) {
var curDelay = $(this).data('sec');
clearInterval(intervalID); // <-- here
intervalID = setInterval(goSection, curDelay); // <-- here
},
afterRender: function(){
intervalID = setInterval(goSection, curDelay); // <-- here
}
});
function goSection() {
$.fn.fullpage.moveSectionDown();
}