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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13313486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:24:28  来源:igfitidea点击:

Can I emulate a callback function from jquery removeClass?

javascriptjqueryremoveclass

提问by Paul

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?

我正在尝试连续执行这些 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');

回答by Inferpse

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

您似乎正在使用 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);

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

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

回答by mainline

Old Tread but Goolge now him ;-)

旧胎,但现在他是古尔奇 ;-)

jQueries UI has a extend Function for removeClass.

jQueries UI 有一个用于 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/

jQuery-UI 文档:http: //api.jqueryui.com/removeclass/