如何在淡入/淡出数组时添加延迟

时间:2017-09-28 10:43:58

标签: javascript jquery

我试图在淡入和淡出我的脚本之间得到延迟,但我无法让它工作。有人能帮助我吗?

(function animate() {     
  $("#quotes").fadeOut(500, function() {
    index = (index + 1) % quotes.length;
    this.textContent = quotes[index];
  }).fadeIn(500, animate);
})();

2 个答案:

答案 0 :(得分:0)

尝试使用它会起作用。

(function animate() {     
    $("#quotes").fadeIn('slow', function() {
        $(this).delay(5000).fadeOut('slow', animate);
        index = (index + 1) % quotes.length;
        this.textContent = quotes[index];
    })
})(); 

答案 1 :(得分:0)

由于satpal's回复,我能够解决问题: 你试过.delay(间隔)? jsfiddle.net/zceKN/116

这是现在的工作代码:

(function animate() {     
  $("#quotes").fadeOut(500, function() {
    index = (index + 1) % quotes.length;
    this.textContent = quotes[index];
  }).fadeIn(500, animate).delay(4000);
})();

非常感谢!