I'm using the ngAnimate module, but all my ng-if
, ng-show
, etc, are affected by that, I want to leverage ngAnimate for some selected elements. For performance and some bugs in elements that shows and hide very speedy.
thanks.
The ngAnimate module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via callback hooks. Animations are not enabled by default, however, by including ngAnimate the animation hooks are enabled for an AngularJS app.
The ngAnimate module adds and removes classes. The ngAnimate module does not animate your HTML elements, but when ngAnimate notice certain events, like hide or show of an HTML element, the element gets some pre-defined classes which can be used to make animations.
There may be many individual elements with the same animation and the same custom properties. The animations directive can be used to keep the general properties and then animation directive will only mark the elements which should be animated.
Angular's animation system is built on CSS functionality, which means you can animate any property that the browser considers animatable. This includes positions, sizes, transforms, colors, borders, and more. The W3C maintains a list of animatable properties on its CSS Transitions page.
If you want to enable animations for specific elements (as opposed to disabling them for specific elements) you can use the $animateProvider to configure elements with a particular class name (or regex) to animate.
The code below will enable animations for elements that have the angular-animate
class:
var myApp = angular.module("MyApp", ["ngAnimate"]); myApp.config(function($animateProvider) { $animateProvider.classNameFilter(/angular-animate/); })
Here is example markup that includes the angular-animate
class to enable animations:
<div ng-init="items=[1,2,3,4,5,6,7,8,9]"> <input placeholder="Filter with animations." ng-model="f" /> <div class="my-repeat-animation angular-animate" ng-repeat="item in items | filter:f track by item" > {{item}} </div> </div>
Plunker example borrowed and modified from this blog where only the first filter has animations (due to having the angular-animate
class).
Please note that I'm using angular-animate
as an example and it is completely configurable using the .classNameFilter
function.
There are two ways you can disbale animations in AngularJS if you have the module ngAnimate as a dependency on your module:
Disable or enable the animation globally on the $animate service:
$animate.enabled(false);
Disable the animations for a specific element - this must be the element for that angular will add the animationstate css classes (e.g. ng-enter, ...)!
$animate.enabled(false, theElement);
As of Angular 1.4 version you should reverse the arguments:
$animate.enabled(theElement, false);
Documentation for $animate
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With