我有一組4個div,我正在尋找使用jQuery來動畫它們一次,然後延遲使用delay(),然後運行另一組動畫,讓div恢復到原來的配置。下面是我的代碼:jQuery:在一組div上有延遲的多個動畫
//only selectors called 'option1' are affected by delay, and not 'option1 img' or 'option2'
$("#option1").showOption1().delay(3000).hideOption1();
//if i don't attach to #option1, delay doesn't work, but the animations that need to happen simultaneously work
$(document).showOption1().delay(3000).hideOption1();
jQuery.fn.showOption1 = function(){
$("#option2, #option3, #leftColumn").fadeOut(1000);
$("#option1").css("zIndex", "5");
$("#option1").animate({
left: "370px",
}, 1500);
$("#option1 img").animate({
width: "500px",
}, 1500, function(){
$("p.optionText").text('hello');
});
return this;
}
jQuery.fn.hideOption1 = function(){
$("#option1 img").animate({
width: "175px",
}, 1500);
$("#option1").animate({
left: "743px",
}, 1500);
$("#option2, #option3, #leftColumn").fadeIn(2000);
$("#option1").css("zIndex", "1");
return this;
}
我試着運行這兩個功能的兩種方式,對2線和5線2的情況下觀看到showOption1()會運行良好,但隨後只有
$("#option1").animate({
left: "743px",
}, 1500);
將在延遲後從hideOption1()中工作。 hideOption1()的其餘部分在showOption1()完成後立即觸發,忽略延遲。另一方面,如果我運行第5行,hideOption1()中的所有代碼將根據需要同時運行,但會完全忽略延遲,在showOption1()完成後立即運行。如何在延遲後同時運行hideOption1()中的所有代碼?
非常感謝!
首先,謝謝你看這個! 我改變了.fadeOut()和.animate()次是相同的;這是我的錯誤。 我有我的功能,如你第一次建議,但我然後選擇將它們附加到jQuery,以便我可以利用鏈接,並在延遲()之間的命令(可能使用回調函數)。所以你不認爲我可以使用delay()來影響多個選擇器?我可以返回多個選擇器(如返回這個,返回#option2等)? – Waleed 2010-05-16 19:47:58
另外,你能澄清你的意思嗎?「或者,讓選擇器匹配(這個)實際使用,通過類隱藏其他選項,例如」? – Waleed 2010-05-16 19:48:34