我可以从jquery removeClass模拟回调函数吗?

时间:2012-11-09 18:01:35

标签: javascript jquery removeclass

我正在尝试连续执行这些removeClass调用。似乎没有使用removeClass的回调函数,所以有另一种方法来模拟这个吗?

  $("#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');

2 个答案:

答案 0 :(得分:8)

您似乎正在使用CSS3过渡来执行此操作。 最简单的方法是手动设置延迟:

$("#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);

没有内置的jQuery方法来检查css转换是否完整。

答案 1 :(得分:0)

旧鞋履,但现在Goolge是他;-)

jQueries用户界面具有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文档:http://api.jqueryui.com/removeclass/