1

我正在尝试淡入和淡出一个元素,但是中间有一点暂停,它可以在没有暂停的情况下工作,但是当我使用 jQuery delay() 函数添加暂停时,它只是在第一个 fadeOut() 之后停止;

这是代码:

$('#headerimage2').each(function(){
for(i=1;i<50;i++){
    $(this).fadeOut(1200).delay(1000).fadeIn(1000).delay(1000);
    }
});

为什么延迟()函数(第一个和第二个)会打破循环?

4

2 回答 2

4

在黑暗中拍摄,但你确定你使用的是 1.4 版的库。这是该版本的新功能。

于 2010-04-24T19:00:40.193 回答
1

您发布的代码在最新的 jquery 中完美地在 Firefox、safari 和 chrome 中运行:

<!DOCTYPE html>
<html>
<head>
  <style>
div { width: 60px; height: 60px; float: left; }
.first { background-color: #3f3; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<p><button>Run</button></p>
<div id='headerimage2' class="first"></div>
<script>
    $("button").click(function() {
    $('#headerimage2').each(function(){
    for(i=1;i<5;i++){
        $(this).fadeOut(100).delay(500).fadeIn(100).delay(500);
       }
    });
    });
</script>
</body>
</html>
于 2010-04-24T19:05:03.773 回答