0

我对 jQuery 很陌生,我正在练习淡入淡出,从一张图像开始,然后继续到下一张图像,依此类推。我已经编写了一段代码(如下),但想知道是否有更简单或更优雅的方式来编写它?我尝试了 each() 函数,但似乎没有用:

    <script type="text/javascript" src="jquery/jquery-1.8.2 .min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    //alert($("div img").length);
    $("div img").css("display","none");
    var delayAmt=0;
    for(var x=0;x<$("div img").length;x++){
        $("div img:eq("+x+")").delay(delayAmt).fadeIn(1000);
        delayAmt+=250;
    }
});
</script>

</head>

<body>
<h1>Ripple fade in.</h1>
<div>
<img src="images/hot.jpg" id="target0">
<img src="images/hot.jpg" id="target1">
</div>
</body>
</html>
4

1 回答 1

1

HTML:

<body>
<h1>Ripple fade in.</h1>
<div id="images">
<img src="images/hot.jpg" id="target0">
<img src="images/hot.jpg" id="target1">
</div>
</body>
</html>​​​

jQuery:

$(document).ready(function(){
   var delay=0;
   $('#images').children('img').each(function () {
      $(this).css("display","none");
      $(this).delay(delay).fadeIn(1800);
      delay += 1000;
   }); 
});

jsFiddle 链接在这里:http: //jsfiddle.net/salih0vicX/6GZt6/

于 2012-11-14T19:14:31.073 回答