我的页面上有2个按钮:#signin and #signup
。点击它们的功能看起来像下面的代码。问题是,当你不断点击它们时,在函数执行之间出现很大的延迟。无论如何都要同时执行它们吗?
var counter = 0,signin = $("#signin"), signup = $("#signup"), signin_f = $("#signin_form"), holder = $("#holder"), signup_f = $("#signup_form"), f_container = $("#form_container");
$(".button").click(function () {
if (counter === 0) {
signin.removeClass('default_radius').addClass('right_radius');
signup.removeClass('default_radius').addClass('left_radius');
$("#first").animate({
marginTop: "-=150px",
}, 500);
}
});
$("#signup").click(function () {
if (counter === 0) {
holder.addClass('red_border').height(275).slideDown("slow");
f_container.show();
signup_f.fadeIn(1200);
} else {
holder.animate({height:"275"},1000).switchClass( "green_border", "red_border", 1000 );
signin_f.fadeOut(500);
f_container.animate({height:"260"},1000);
signup_f.fadeIn(1000);
}
counter++;
});
$("#signin").click(function () {
if (counter === 0) {
holder.addClass('green_border').height(125).slideDown("slow");
f_container.show();
signin_f.fadeIn(1200);
} else {
holder.animate({height:"125"},1000).switchClass( "red_border", "green_border", 500 );
signup_f.fadeOut(500);
f_container.animate({height:"110"},1000);
signin_f.fadeIn(1200);
}
counter++;
});
您可以在此处查看代码:http://tural.no-ip.org。快速并持续点击按钮,你会看到我在说什么。外部js文件:first.js。
答案 0 :(得分:3)
在添加其他fade
功能之前使用.stop()
方法。用法:
signin_f.stop(true, true).fadeIn(1200);
//First argument true = Remove queued animations as well
//Second argument true = Immediately finish the current animation