最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I emulate a callback function from jquery removeClass? - Stack Overflow

programmeradmin3浏览0评论

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');

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');
Share Improve this question asked Nov 9, 2012 at 18:01 PaulPaul 11.8k32 gold badges92 silver badges145 bronze badges 2
  • there's no waiting for removing a class from an element.you remove it and add it.what's the point? – Hojat Jafari Commented Nov 9, 2012 at 18:06
  • It's part of transitions with CSS3 so I'm looking for a fun effect. – Paul Commented Nov 9, 2012 at 18:07
Add a ment  | 

2 Answers 2

Reset to default 8

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 plete.

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

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

发布评论

评论列表(0)

  1. 暂无评论