rstacruz / jquery.transit

Super-smooth CSS3 transformations and transitions for jQuery
http://ricostacruz.com/jquery.transit
7.29k stars 864 forks source link

.complete is called twice. Before and after a transition #135

Open dan-lee opened 11 years ago

dan-lee commented 11 years ago

My .complete callback is called before the transition and after. I have to use this workaround to use it under current circumstances:


var c = 0;
el.transition({
  // ...
  complete: function() {
    if (++c % 2 == 0) {
      // ...
    }
  }
});
matthew-dean commented 11 years ago

Yep, having the same issue.

dan-lee commented 11 years ago

Okay, this bug appears to be a bug of this pull request: rstacruz/jquery.transit#134

nibblebot commented 11 years ago

critical issue....

skevy commented 11 years ago

Up vote on this one.

hannesjohansson commented 10 years ago

If you want to be compatible with jQuery animate, you should pass the complete call in the second object parameter

var c = 0;
el.transition({
  // ...
},
{
  complete: function() {
    if (++c % 2 == 0) {
      // ...
    }
  }
});

See: https://github.com/rstacruz/jquery.transit/pull/170

rolbr commented 10 years ago

+1

Since the docs (https://github.com/rstacruz/jquery.transit#animating---fntransition) explicitly state that you can define the complete-callback within the first object, I wasn't hesitating to do exactly that, which resulted in the callback being called twice.

However, putting the complete-callback into the second object just as hannesjohansson pointed out above, does indeed remedy this issue.

I love adding everything to the first object though, because it looks much cleaner ;)

hannesjohansson commented 10 years ago

I agree that it is cleaner but it completely breaks compatibility with jquery.animate. If you put the callback inside of the first object in animate it doesn't run, so the documentation for transit is kind of flawed.

Example of jQuery not accepting a callback function in the first object param: http://codepen.io/anon/pen/fErzb

okonet commented 10 years ago

Following semver, no matter what decision will be made on jQuery.animate compatibility issue (#170), this breaking change should be fixed and released as a next patch version. And if the decision will be made to break the current API, there should be a separate release under at least next minor version.

Right now everybody who is using npm's and bower's defaults to define dependencies in *.json files like ~x.x or ^x.x is experiencing lots of pain and frustration!