Jquery FadeIn和Out on Multiple Divs

时间:2013-04-16 18:49:43

标签: jquery jquery-animate fadein fadeout

我是用来淡化div进出口的脚本。它在一个上工作正常但在另一个上根本不工作。有谁知道为什么?这是它的小提琴http://jsfiddle.net/MeEc6/

这是JavaScript:

$(document).ready(function()                         

    {  var book = $('#book');
       var synopsis = $('#synopsis');
function runIt() {
   synopsis.animate({opacity:'+=1'}, 1000);
   synopsis.animate({opacity:'-=0.9'}, 2000, runIt).delay(2000);
}
       runIt();});

2 个答案:

答案 0 :(得分:1)

据我所知,您希望在booksynopsis上执行相同的动画,但您只需在animate上添加synopsis方法:

EXAMPLE

function runIt() {
   synopsis.animate({opacity:'+=1'}, 1000);
   synopsis.animate({opacity:'-=0.9'}, 2000, runIt).delay(2000);

   book.animate({opacity:'+=1'}, 1000);
   book.animate({opacity:'-=0.9'}, 2000, runIt).delay(2000);
}

答案 1 :(得分:1)

向两者添加一个类:http://jsfiddle.net/MeEc6/3/

<div id="synopsis" class="fader">
    <img src="http://www.unearthingfilm.com/images/interface/shine.png" width="150" height="150" />
</div>
<!-- End of Synopsis -->
<div id="book" class="fader">
    <img src="http://www.unearthingfilm.com/images/bookGlow.png" width="365" height="347" />
</div>

并制作动画:

var synopsis = $('.fader');