disable nganimate for some elements

2019-01-07 06:55发布

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.

9条回答
啃猪蹄的小仙女
2楼-- · 2019-01-07 07:07

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.

查看更多
趁早两清
3楼-- · 2019-01-07 07:09

thanks, i wrote a directive which you can place on the element

CoffeeScript:

myApp.directive "disableAnimate", ($animate) ->
  (scope, element) ->
    $animate.enabled(false, element)

JavaScript:

myApp.directive("disableAnimate", function ($animate) {
    return function (scope, element) {
        $animate.enabled(false, element);
    };
});
查看更多
\"骚年 ilove
4楼-- · 2019-01-07 07:09

I do NOT want to use ngAnimate on my ng-if's, so this would be my solution:

[ng-if] {
  .ng-enter, .ng-leave, .ng-animate {
    -webkit-transition: none !important;
    transition: none !important;
  }
}

Just posting this as another suggestion!

查看更多
Root(大扎)
5楼-- · 2019-01-07 07:10

I know that it is a delayed reply, but here we use in MainController:

// disable all animations
$animate.enabled(false);

But the problem is that when we disable all animations, the ui-select are configured to opacity: 0.

So, its necessary to set opacity to 1 using CSS:

.ui-select-choices {
    opacity: 1 !important;
}

This will properly set opacity and the ui-select will work.

查看更多
对你真心纯属浪费
6楼-- · 2019-01-07 07:14

Just add this to your CSS. It is best if it is the last rule:

.no-animate {
   -webkit-transition: none !important;
   transition: none !important;
}

then add no-animate to the class of element you want to disable. Example:

<div class="no-animate"></div>
查看更多
Anthone
7楼-- · 2019-01-07 07:18

To disable ng-animate for certain elements, using a CSS class, which follows Angular animate paradigm, you can configure ng-animate to test the class using regex.

Config

    var myApp = angular.module("MyApp", ["ngAnimate"]);
    myApp.config(function($animateProvider) {
        $animateProvider.classNameFilter(/^(?:(?!ng-animate-disabled).)*$/);
    })

Usage

Simply add the ng-animate-disabled class to any elements you want to be ignored by ng-animate.


Credit http://davidchin.me/blog/disable-nganimate-for-selected-elements/

查看更多
登录 后发表回答