|
39 | 39 | * return {
|
40 | 40 | * enter: function(element, doneFn) {
|
41 | 41 | * var height = element[0].offsetHeight;
|
42 |
| - * var animator = $animateCss(element, { |
| 42 | + * return $animateCss(element, { |
43 | 43 | * from: { height:'0px' },
|
44 | 44 | * to: { height:height + 'px' },
|
45 | 45 | * duration: 1 // one second
|
46 | 46 | * });
|
47 |
| - * animator.start().done(doneFn); |
48 | 47 | * }
|
49 | 48 | * }
|
50 | 49 | * }]);
|
|
67 | 66 | * return {
|
68 | 67 | * enter: function(element, doneFn) {
|
69 | 68 | * var height = element[0].offsetHeight;
|
70 |
| - * var animator = $animateCss(element, { |
| 69 | + * return $animateCss(element, { |
71 | 70 | * addClass: 'red large-text pulse-twice',
|
72 | 71 | * easing: 'ease-out',
|
73 | 72 | * from: { height:'0px' },
|
74 | 73 | * to: { height:height + 'px' },
|
75 | 74 | * duration: 1 // one second
|
76 | 75 | * });
|
77 |
| - * animator.start().done(doneFn); |
78 | 76 | * }
|
79 | 77 | * }
|
80 | 78 | * }]);
|
|
171 | 169 | * applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties
|
172 | 170 | * and that changing them will not reconfigure the parameters of the animation.
|
173 | 171 | *
|
174 |
| - * By calling `animation.start()` we do get back a promise, however, due to the nature of animations we may not want to tap into the default behaviour of |
175 |
| - * animations (since they cause a digest to occur which may slow down the animation performance-wise). Therefore instead of calling `then` to capture when |
176 |
| - * the animation ends be sure to call `done(callback)` (this is the recommended way to use `$animateCss` within JavaScript-animations). |
| 172 | + * ### runner.done() vs runner.then() |
| 173 | + * It is documented that `animation.start()` will return a promise object and this is true, however, there is also an additional method available on the |
| 174 | + * runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**. |
| 175 | + * Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()` |
| 176 | + * unless you really need a digest to kick off afterwards. |
177 | 177 | *
|
178 |
| - * The example below should put this into perspective: |
179 |
| - * |
180 |
| - * ```js |
181 |
| - * var animator = $animateCss(element, { ... }); |
182 |
| - * animator.start().done(function() { |
183 |
| - * // yaay the animation is over |
184 |
| - * doneCallback(); |
185 |
| - * }); |
186 |
| - * ``` |
| 178 | + * Keep in mind that, to make this easier, ngAnimate has tweaked the JS animations API to recognize when a runner instance is returned from $animateCss |
| 179 | + * (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code). Check the [animation code above](#usage) to see how this works. |
187 | 180 | *
|
188 | 181 | * @param {DOMElement} element the element that will be animated
|
189 | 182 | * @param {object} options the animation-related options that will be applied during the animation
|
|
0 commit comments