Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I emulate a callback function from jquery removeClass?

I'm trying to execute these removeClass calls in succession. There doesn't seem to be a call back function using removeClass so is there another way to emulate this?

  $("#card1").removeClass('flip');

  //wait for card1 flip to finish and then flip 2
  $("#card2").removeClass('flip');

  //wait for card2 flip to finish and then flip 3
  $("#card3").removeClass('flip');
like image 670
Paul Avatar asked Nov 09 '12 18:11

Paul


People also ask

How to removeClass using jQuery?

jQuery removeClass() MethodThe removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.

What is jQuery callback function?

jQuery Callback Functions JavaScript statements are executed line by line. However, with effects, the next line of code can be run even though the effect is not finished. This can create errors. To prevent this, you can create a callback function. A callback function is executed after the current effect is finished.

How to replace classes in jQuery?

In jQuery, to replace one class properties with another, there is a function called replaceClass() through which it takes in two different class names the first class name is specified as a class which should be replaced with the second class name that is specified as the second parameter in the function, where it ...


2 Answers

It seems that you're using CSS3 transition for doing this. The easiest way to do this is to set delay manually:

$("#card1").removeClass('flip');

setTimeout(function(){
   //wait for card1 flip to finish and then flip 2
   $("#card2").removeClass('flip');
}, 500);

setTimeout(function(){
   //wait for card2 flip to finish and then flip 3
   $("#card3").removeClass('flip');
}, 1000);

There's no built in jQuery method to check that css transition is complete.

like image 191
Inferpse Avatar answered Sep 25 '22 00:09

Inferpse


Old Tread but Goolge know him ;-)

jQueries UI has a extend Function for removeClass.

<div class="big-blue"></div>
$( "div" ).click(function() {
  $( this ).removeClass( "big-blue", 1000, "easeInBack", function(){
      // do fancy stuff after animation is completed
  });
});

jQuery-UI Doc: http://api.jqueryui.com/removeclass/

like image 30
mainline Avatar answered Sep 23 '22 00:09

mainline