2012-05-07 48 views
0

下面的代碼有效,但新圖像不會淡入,直到前一個淡出。我希望它們同時淡入淡出,使其看起來好像新圖像在舊圖像上消失。同時淡入和淡出

HTML

<img id="BiblesandCommentaries_bg" src="_\images\backgrounds\BiblesandCommentaries_bg.jpg"/> 
<img id="EnquirersLibrary_bg" src="_\images\backgrounds\EnquirersLibrary_bg.jpg"/> 
<img id="NewBelievers_bg" src="_\images\backgrounds\NewBelievers_bg.jpg"/> 
<img id="ChristianLiving_bg" src="_\images\backgrounds\ChristianLiving_bg.jpg"/> 
<img id="FamilyLibrary_bg" src="_\images\backgrounds\FamilyLibrary_bg.jpg"/> 
<img id="YoungAdultLibrary_bg" src="_\images\backgrounds\YoungAdultLibrary_bg.jpg"/> 
<img id="WorshipLibrary_bg" src="_\images\backgrounds\WorshipLibrary_bg.jpg"/> 
<img id="BibleTeachings_bg" src="_\images\backgrounds\BibleTeachings_bg.jpg"/> 
<img id="Leadership_bg" src="_\images\backgrounds\Leadership_bg.jpg"/> 
<img id="SchoolofChrist_bg" src="_\images\backgrounds\SchoolofChrist_bg.jpg"/> 

JS

$('#sidebar a').click(function() { 
    $('#BiblesandCommentaries_bg, #EnquirersLibrary_bg, #NewBelievers_bg, #ChristianLiving_bg, #FamilyLibrary_bg, #YoungAdultLibrary_bg, #WorshipLibrary_bg, #BibleTeachings_bg, #Leadership_bg, #SchoolofChrist_bg').fadeTo("slow", 0); 
    bgImage = $(this).attr('href')+'_bg'; 
    $(bgImage).fadeTo("slow", 1); 
}); 
+0

可能的Dupl icate:http://stackoverflow.com/questions/811750/how-can-i-get-jquery-to-execute-animations-in-exact-parallel – JaredMcAteer

回答

2

當你打電話的元素有關的淡入動畫,所以儘量不要淡出這應該在正在消失的元素其他淡出動畫仍在執行代碼是這樣的:(我加了.not(bgImage)部分)

$('#sidebar a').click(function() { 
    var bgImage = $(this).attr('href')+'_bg';  
    $('#BiblesandCommentaries_bg, #EnquirersLibrary_bg, #NewBelievers_bg, #ChristianLiving_bg, #FamilyLibrary_bg, #YoungAdultLibrary_bg, #WorshipLibrary_bg, #BibleTeachings_bg, #Leadership_bg, #SchoolofChrist_bg').not(bgImage).fadeTo("slow", 0);  
    $(bgImage).fadeTo("slow", 1); 
}); 
+0

美麗,將標記爲完整 – Blainer