0

I would like a button to blink for a short duration prior to a AJAX call (and some other animations happening). The ajax call happens very fast so I do not want to use AJAX's before function. The blink must be distinct prior to any other animations. I feel as if there is a prettier way to do this:

       //This is inside of a button click event
       $(this).addClass('active').delay(250).queue(function (e) {
            $(this).removeClass('active').delay(250).queue(function (f) {
                alert(33);
                $child.css('margin-left', $(window).width() + 10 + 'px');
                $child.load(url + 'API CALL' + $(this).data("id"), bindAClicks);
            });
        });

bindAClicks - Animates to margin:0.

$child is a container div.

active is a class with a dark background.

What's wierd is that the alert is not even firing.

user974896
  • 1,795
  • 4
  • 28
  • 48
  • If you are referring to beforeSend, I would recommend checking out this answer which shows how to wait for your animation to finish before. http://stackoverflow.com/questions/5212949/jquery-ajax-wait-until-beforesend-animation-finishes – JasCav Jul 26 '12 at 16:29
  • Thank you. This AJAX is just one example. I need the same functionality on my non ajax buttons as well. If you make this into an answer I will give you rep – user974896 Jul 26 '12 at 16:49
  • Why do it "prior"? AJAX is async, initiate request and blink your button while waiting for response. – Oleg V. Volkov Jul 26 '12 at 17:10
  • The response is so quick that you can't see the blink. – user974896 Jul 26 '12 at 18:43
  • @user974896 - Made an answer. Also added an example with a blink and using Ajax. – JasCav Jul 26 '12 at 20:19

1 Answers1

0

If you are referring to beforeSend, I would recommend checking out this answer which shows how to wait for your animation to finish.

In response to Oleg's comment, I'm not sure what problem you're having when you say the response is so quick you can't see the blink. I created a quick example to demonstrate how it would work (so you can make the Ajax call and still perform the blink). Hopefully this helps.

Community
  • 1
  • 1
JasCav
  • 34,458
  • 20
  • 113
  • 170