Javascript 同时运行jquery事件
所以我有一个jquery测试。要开始测验,您必须单击“开始”按钮。单击后,标题文本被删除,测验垂直居中(所有这一切应该同时发生)。但是,由于我的代码,标题文本将被删除,然后测验将居中。如何使它们同时运行 这是我的错误代码:Javascript 同时运行jquery事件,javascript,jquery,javascript-events,fadeout,simultaneous,Javascript,Jquery,Javascript Events,Fadeout,Simultaneous,所以我有一个jquery测试。要开始测验,您必须单击“开始”按钮。单击后,标题文本被删除,测验垂直居中(所有这一切应该同时发生)。但是,由于我的代码,标题文本将被删除,然后测验将居中。如何使它们同时运行 这是我的错误代码: $('#get-started').click(function(){ $('#index-banner').fadeOut(200, "swing"); $('#begin-exam').delay(210).fadeOut(180, "swing")
$('#get-started').click(function(){
$('#index-banner').fadeOut(200, "swing");
$('#begin-exam').delay(210).fadeOut(180, "swing");
setTimeout(function(){
$('#content').animate({top:'25%'},700).addClass('center-exam');
}, 209);
});
“中心考试”类只是在测验中添加了一个“绝对”位置,这样当你将.animate和.addClass链接在一起时,它就可以垂直居中了,方法是将它们与“.”连接起来。一个运行并完成,另一个运行。通过将它们放在单独的语句中,它们可以并且将尽可能地并行运行
$('#get-started').click(function(){
$('#index-banner').fadeOut(200, "swing");
$('#begin-exam').delay(210).fadeOut(180, "swing");
setTimeout(function(){
$('#content').animate({top:'25%'},700);
$('#content').addClass('center-exam');
}, 209);
});
将.animate和.addClass与“.”连接在一起时,一个运行并完成,另一个运行。通过将它们放在单独的语句中,它们可以并且将尽可能地并行运行
$('#get-started').click(function(){
$('#index-banner').fadeOut(200, "swing");
$('#begin-exam').delay(210).fadeOut(180, "swing");
setTimeout(function(){
$('#content').animate({top:'25%'},700);
$('#content').addClass('center-exam');
}, 209);
});
是否需要其他解释来改进您的答案?是否需要其他解释来改进您的答案?