我正在使用此函数来延迟向项目添加动画类时,他们进来查看。如何更新setInterval延迟?
$(function() {
var itemQueue = [];
var queueTimer;
function processItemQueue() {
var $delay = 100; // needs to be based on item data-delay attr
if (queueTimer) {
return;
}
queueTimer = window.setInterval(function() {
if (itemQueue.length) {
var $firstinque = $(itemQueue.shift());
var $animation = $firstinque.attr('data-effect');
$firstinque.addClass($animation);
} else {
window.clearInterval(queueTimer);
queueTimer = null;
}
}, $delay);
}
$(".item-animate").waypoint(function() {
itemQueue.push(this.element);
processItemQueue();
}, {
offset: '90%'
})
});
基本功能工作正常,但我需要设置基于项目的数据延迟属性的延迟,我不能做到这一点的setInterval内。请参阅上面的小提琴获取更多信息。小提琴中的第二个项目延迟了500毫秒,所以它应该在晚些时候启动。 任何帮助表示赞赏。
[更改的setInterval的时间间隔,而它的运行]的可能的复制(HTTP ://stackoverflow.com/questions/1280263/changing-the-interval-of-setinterval-while-its-running) – Xufox
你不能改变时间一旦定义了setInterval或setTimeout的值 - 你所能做的就是放弃它并重新创建它。 – Soren
而不是使用应该使用固定延迟和重复的setInterval,将一串setTimeouts串联在一起,这只会在固定的延迟时间内触发一次。 – James