Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable nganimate for some elements

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.

like image 669
drtobal Avatar asked Jan 21 '14 04:01

drtobal


People also ask

What is ngAnimate?

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.

What is ngAnimate in AngularJS?

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.

Can animations be achieved with custom directive?

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.

What is angular animation?

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.


2 Answers

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.

like image 193
Gloopy Avatar answered Sep 28 '22 13:09

Gloopy


There are two ways you can disbale animations in AngularJS if you have the module ngAnimate as a dependency on your module:

  1. Disable or enable the animation globally on the $animate service:

    $animate.enabled(false); 
  2. 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.

like image 30
michael Avatar answered Sep 28 '22 13:09

michael