0

There are 2 buttons on my page: #signin and #signup. Click functions for them look like code below. The problem is, when you continously click on them, appearing big delay between functions' execution. Is there anyway to execute them at the same time?

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++;
    });

You can see the code in action here: http://tural.no-ip.org . Fast and continuously click on button and you'll se what i'm talking about. External js file: first.js.

2
  • I'd rely on CSS to automatically resize. Commented Nov 12, 2011 at 21:00
  • tried with css too. animations stops 1-2 sec while css "reconfiguring" itself Commented Nov 12, 2011 at 21:02

1 Answer 1

3

Use the .stop() method before adding another fade function. Usage:

signin_f.stop(true, true).fadeIn(1200);
//First argument true = Remove queued animations as well
//Second argument true = Immediately finish the current animation
Sign up to request clarification or add additional context in comments.

2 Comments

tried no success. tural.no-ip.org . Fast and continuously click on button and you'll se what i'm talking about. External js file: first.js.
Also add .stop(true, true) before animate(). Instead, you can also add signin_f.stop(true, true) at the beginning of each event listener.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.