我有一组 4 个 div,我希望使用 jQuery 为它们设置一次动画,然后使用 delay() 延迟,然后在它们上运行另一组动画,将 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() 中的所有代码同时运行?
提前非常感谢!