What is angular-animate?
The angular-animate package is an AngularJS module that provides support for JavaScript, CSS3 transition, and CSS3 keyframe animation hooks within your AngularJS applications. It allows you to create smooth, complex animations for various elements and states in your application.
What are angular-animate's main functionalities?
CSS-based animations
This feature allows you to define CSS classes for entering and leaving animations. The .ng-enter and .ng-leave classes are used to define the starting state of the animation, while the .ng-enter-active and .ng-leave-active classes define the end state.
/* CSS code */
.fade.ng-enter {
transition: 0.5s linear all;
opacity: 0;
}
.fade.ng-enter-active {
opacity: 1;
}
.fade.ng-leave {
transition: 0.5s linear all;
opacity: 1;
}
.fade.ng-leave-active {
opacity: 0;
}
JavaScript-based animations
This feature allows you to define animations using JavaScript. You can create custom animations for entering and leaving elements by manipulating their CSS properties and using jQuery's animate function.
// JavaScript code
angular.module('myApp', ['ngAnimate'])
.animation('.slide', function() {
return {
enter: function(element, done) {
element.css({
position: 'relative',
left: '-10px',
opacity: 0
});
element.animate({
left: '0px',
opacity: 1
}, 1000, done);
},
leave: function(element, done) {
element.css({
position: 'relative',
left: '0px',
opacity: 1
});
element.animate({
left: '-10px',
opacity: 0
}, 1000, done);
}
};
});
ngAnimate directive
The ngAnimate directive can be used to apply animations to elements within an AngularJS application. In this example, the .fade class is applied to each item in the ng-repeat directive, and the corresponding CSS animations are triggered when items are added or removed.
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="item in items" class="fade">
{{item}}
</div>
</div>
<script>
angular.module('myApp', ['ngAnimate'])
.controller('myCtrl', function($scope) {
$scope.items = ['Item 1', 'Item 2', 'Item 3'];
});
</script>
Other packages similar to angular-animate
ng2-animate
ng2-animate is an Angular (2+) module that provides a set of reusable animations for Angular applications. It offers a variety of pre-built animations that can be easily applied to elements, making it simpler to add animations without writing custom CSS or JavaScript. Compared to angular-animate, ng2-animate is designed for newer versions of Angular and provides a more modern approach to animations.
react-transition-group
react-transition-group is a popular library for managing animations in React applications. It provides components like Transition, CSSTransition, and TransitionGroup to handle the entering and exiting of elements with animations. While it serves a similar purpose to angular-animate, it is specifically designed for React and offers a different API and set of features tailored to React's component-based architecture.
animejs
animejs is a lightweight JavaScript animation library that works with any JavaScript framework, including AngularJS. It provides a powerful and flexible API for creating complex animations with minimal code. Unlike angular-animate, which is tightly integrated with AngularJS, animejs is a general-purpose animation library that can be used across different frameworks and projects.
packaged angular-animate
This repo is for distribution on npm
and bower
. The source for this module is in the
main AngularJS repo.
Please file issues and pull requests against that repo.
Install
You can install this package either with npm
or with bower
.
npm
npm install angular-animate
Then add ngAnimate
as a dependency for your app:
angular.module('myApp', [require('angular-animate')]);
bower
bower install angular-animate
Then add a <script>
to your index.html
:
<script src="/bower_components/angular-animate/angular-animate.js"></script>
Then add ngAnimate
as a dependency for your app:
angular.module('myApp', ['ngAnimate']);
Documentation
Documentation is available on the
AngularJS docs site.
License
The MIT License
Copyright (c) 2010-2015 Google, Inc. http://angularjs.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1.4.9 implicit-superannuation (2016-01-21)
Bug Fixes
- Animation
- ensure that animate promises resolve when the document is hidden
(9a60408c)
- do not trigger animations if the document is hidden
(09f6061a,
#12842, #13776)
- only copy over the animation options once
(2fc954d3,
#13722, #13578)
- allow event listeners on document in IE
(5ba4419e,
#13548, #13696)
- allow removing classes that are added by a running animation
(6c4581fc,
#13339, #13380, #13414, #13472, #13678)
- do not use
event.timeStamp
anymore for time tracking
(620a20d1,
#13494, #13495) - ignore children without animation data when closing them
(be01cebf,
#11992, #13424)
- do not alter the provided options data
(7a81e6fe,
#13040, #13175)
- correctly handle
$animate.pin()
host elements
(a985adfd,
#13783) - allow animations when pinned element is parent element
(4cb8ac61,
#13466)
- allow enabled children to animate on disabled parents
(6d85f24e,
#13179, #13695)
- correctly access
minErr
(0c1b54f0) - ensure animate runner is the same with and without animations
(937942f5,
#13205, #13347)
- remove animation end event listeners on close
(d9157849,
#13672)
- consider options.delay value for closing timeout
(592bf516,
#13355, #13363)
- $controller: allow identifiers containing
$
(2563ff7b,
#13736) - $http: throw if url passed is not a string
(c5bf9dae,
#12925, #13444)
- $parse: handle interceptors with
undefined
expressions
(7bb2414b) - $resource: don't allow using promises as
timeout
and log a warning
(47486524) - formatNumber: cope with large and small number corner cases
(9c49eb13,
#13394, #8674, #12709, #8705, #12707, #10246, #10252)
- input:
- isArrayLike: recognize empty instances of an Array subclass
(323f9ab7,
#13560, #13708)
- ngInclude: do not compile template if original scope is destroyed
(9590bcf0)
- ngOptions:
- select: re-define
ngModelCtrl.$render
in the select
directive's postLink function
(529b2507,
#13583, #13583, #13663)
Minor Features
Performance Improvements
- ngAnimate: speed up
areAnimationsAllowed
check
(2d3303dd)
Breaking Changes
While we do not deem the following to be a real breaking change we are highlighting it here in the
changelog to ensure that it does not surprise anyone.
Possible breaking change for users who updated their code to provide a timeout
promise for a $resource
request in version v1.4.8.
Up to v1.4.7 (included), using a promise as a timeout in $resource
, would silently
fail (i.e. have no effect).
In v1.4.8, using a promise as timeout would have the (buggy) behaviour described
in https://github.com/angular/angular.js/pull/12657#issuecomment-152108887.
(I.e. it will work as expected for the first time you resolve the promise and will
cancel all subsequent requests after that - one has to re-create the resource
class. This was not documented.)
With this change, using a promise as timeout in v1.4.9 onwards is not allowed.
It will log a warning and ignore the timeout value.
If you need support for cancellable $resource
actions, you should upgrade to
version 1.5 or higher.
<a name="1.5.0-rc.1"></a>