-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngAnimate addClass/removeClass: Callback after addClass, as well as after transitionend #5053
Comments
Adding extra callback fns to $animate.event(...) should do the job. Here is a breakdown of how $animate works right now.
Something like: $animate.enter(element, parent, after, {
before : function() { }, //before the DOM operation
after : function() { }, //just after the DOM operation
close : function(wasCancelled) { } //when the animation is complete
}); the before and after callbacks should give you the hooks to place the class in to avoid any jumping. And this wouldn't cause any breaking changes in 1.2. Keep in mind that the callbacks would work in conjunction with JS animations as well (so there wouldn't be a callback specific to transitions, but if you're only using transitions then it would be specific to that).
|
Thanks for the reply So yeah, the issue is that without being able to perform any additional DOM manipulation after addClass (but before a reflow, say), the close callback ends up firing pretty much ASAP, and you end up with a jumpy effect. It's not always possible to perform additional DOM manipulation before addClass (for the same reason --- jumpy effect and immediate callback). The "workaround" is to add classes, perform the DOM manipulation in the close callback, and wait an arbitrary length of time (or bind to transitionend, or what have you) --- but these things all kind of suck (and potentially break older browsers who are never going to fire transitionend). So, I think the "object of callbacks" thing is not terrible (in terms of not breaking the API) and would solve this problem for me (and apparently others), so I guess that's a good thing. I saw the other animation fixes merge today, so if I have time I can see if this solution actually solves the problem tomorrow |
@caitp I'm scrapping the solution to treat the callback param as a collection of callbacks. Instead what $animate will do is fire callback functions on the element. $animate.enter(element, parent);
element.on('$animate:start', function(data) {
//data.className
//data.event
});
element.on('$animate:close', function(data) {
//data.className
//data.event
//data.cancelled
}); This way you can listen on animation events in other directives as well as child directives. This is almost ready and should be done by tomorrow or Friday. |
I’m not sure I like the idea of using triggered events without something like jQuery.fn.one() to automatically unbind I can see how it would be simpler to implement, but is it really a good idea? Caitlin Potter On Nov 28, 2013, at 12:18 AM, Matias Niemelä [email protected] wrote:
|
Yeah I thought about that too. I'm also planning on putting in |
Alright so |
i'm not sure if this is related. |
@nissoh very strange indeed. Can you possibly open a new issue and reference me in there please? |
@nissoh did you find a way to catch the done callback? |
@bbshopadmin this what we're planning on doing: 3830 |
Once |
Closes angular#5685 Closes angular#5053 Closes angular#4993
Closes angular#5685 Closes angular#5053 Closes angular#4993
Thank you so much @matsko this has helped a lot! |
So, there are a few things --- In some cases, adding a class needs to be paired with an actual DOM operation (which can't take place before adding the class, this would lead to an instant jump) --- So having a sort of before transition, after adding transition class callback would be a pretty big deal.
Following this, on most browsers you won't see a transitionend event fired immediately (because no transition will have occurred if the class is added before a DOM operation such as changing the height or position or something of the animated element) happens --- So, if a transitionend were to happen immediately, the first instance should be ignored (if supplied with a "DOM manipulation"/pre-transition callback)
Finally, the proper transitionend/post-duration callback should not trigger the doneCallback until after it's actually completed (or alternatively, why not have
$animate.addClass/removeClass/enter/leave()
return a promise?I am not talking about "module animations" registered via
module.animation()
here, because in some cases these are not practical to use.Clearly there are some breaking changes listed, although I think these changes could be written in a way which would provide API compatibility with 1.2.0. I may try to get something like this working after matsko@'s ngAnimate fixes are merged.
(These views come from attempting to add some ngAnimate functionality to angular-ui/bootstrap, which has typically required listening for transitionend or waiting for a delay/duration manually)
The text was updated successfully, but these errors were encountered: