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
Add a <script>
to your index.html
:
<script src="/node_modules/angular-animate/angular-animate.js"></script>
Then add ngAnimate
as a dependency for your app:
angular.module('myApp', ['ngAnimate']);
Note that this package is not in CommonJS format, so doing require('angular-animate')
will
return undefined
.
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-2012 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.3.6 robofunky-danceblaster (2014-12-08)
Bug Fixes
- $browser: prevent infinite digests when clearing the hash of a url
(10ac5948,
#9629, #9635, #10228, #10308)
- $http: preserve config object when resolving from cache
(facfec98,
#9004, #9030)
- $location:
- $parse:
- fix operators associativity
(ed1243ff)
- follow JavaScript context for unbound functions
(429938da)
- filterFilter:
- inputs: ignoring input events in IE caused by placeholder changes or focus/blur on inputs with placeholders
(55d9db56,
#9265)
- linky: make urls starting with www. links, like markdown
(915a891a,
#10290)
- ngAnimate: do not use jQuery class API
(40a537c2,
#10024, #10329)
- ngMock: allow numeric timeouts in $httpBackend mock
(acb066e8,
#4891)
- ngModel:
- always use the most recent viewValue for validation
(2d6a0a1d,
#10126, #10299)
- fixing many keys incorrectly marking inputs as dirty
(d21dff21)
- ngSanitize: exclude smart quotes at the end of the link
(7c6be43e,
#7307)
- numberFilter: numbers rounding to zero shouldn't be negative
(96c61fe7,
#10278)
- orderBy:
- make object-to-primitive behavior work for objects with null prototype
(3aa57528)
- maintain order in array of objects when predicate is not provided
(8bfeddb5,
#9566, #9747, #10311)
Features
- $$jqLite: export jqLite as a private service
(f2e7f875)
- $injector: print caller name in "unknown provider" errors (when available)
(013b522c,
#8135, #9721)
- jsonFilter: add optional arg to define custom indentation
(1191edba,
#9771)
- ngAria: bind keypress on ng-click w/ option
(5481e2cf,
#10288)
Breaking Changes
We no longer throw an ihshprfx
error if the URL after the base path
contains only a hash fragment. Previously, if the base URL was http://abc.com/base/
and the hashPrefix is !
then trying to parse http://abc.com/base/#some-fragment
would have thrown an error. Now we simply assume it is a normal fragment and
that the path is empty, resulting $location.absUrl() === "http://abc.com/base/#!/#some-fragment"
.
This should not break any applications, but you can no longer rely on receiving the
ihshprfx
error for paths that have the syntax above. It is actually more similar
to what currently happens for invalid extra paths anyway: If the base URL
and hashPrfix are set up as above, then http://abc.com/base/other/path
does not
throw an error but just ignores the extra path: http://abc.com/base
.
-
filterFilter: due to a75537d4,
Named properties in the expression object will only match against properties on the same level.
Previously, named string properties would match against properties on the same level or deeper.
Before:
arr = filterFilter([{level1: {level2: 'test'}}], {level1: 'test'}); // arr.length -> 1
After:
arr = filterFilter([{level1: {level2: 'test'}}], {level1: 'test'}); // arr.length -> 0
In order to match deeper nested properties, you have to either match the depth level of the
property or use the special $
key (which still matches properties on the same level
or deeper). E.g.:
// Both examples below have `arr.length === 1`
arr = filterFilter([{level1: {level2: 'test'}}], {level1: {level2: 'test'}});
arr = filterFilter([{level1: {level2: 'test'}}], {$: 'test'});
<a name="1.3.5"></a>