2008-09-16 70 views

回答

32

你可以提供一个回调运行效果完成后的效果功能。

$("#show-projects").click(function() { 
    $(".page:visible").fadeOut("normal", function() { 
     $("#projects").fadeIn("normal"); 
    }); 
}); 
16

你想要的是一个队列。

退房http://api.jquery.com/queue/的参考页一些工作实例。

+0

.queue()是一个元素只功能。如果你有不同的动画目标,这是行不通的。 – Bora 2011-02-17 14:26:20

0

是否必须有目标?当然你可以使用随机目标来顺序排列事件,只要目标是恒定的...下面我使用动画目标的父节点来存储队列。

//example of adding sequential effects through 
//event handlers and a jquery event trigger 
jQuery(document).unbind("bk_prompt_collapse.slide_up"); 
jQuery(document).bind("bk_prompt_collapse.slide_up" , function(e, j_obj) { 
    jQuery(j_obj).queue(function() { 
     //running our timed effect 
     jQuery(this).find('div').slideUp(400); 
     //adding a fill delay to the parent 
     jQuery(this).delay(400).dequeue(); 
    }); 
});      
//the last action removes the content from the dom 
//if its in the queue then it will fire sequentially 
jQuery(document).unbind("bk_prompt_collapse.last_action"); 
jQuery(document).bind("bk_prompt_collapse.last_action" , function(e, j_obj) { 
    jQuery(j_obj).queue(function() { 
     //Hot dog!! 
     jQuery(this).remove().dequeue(); 
    }); 
}); 
jQuery("tr.bk_removing_cart_row").trigger( 
    "bk_prompt_collapse" , 
    jQuery("tr.bk_removing_cart_row") 
); 

不知道其可能的,但好像你可以绑定.dequeue()火时是另一个jQuery事件触发的,而不是在我上面的例子射击在线?有效地停止动画队列?