Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you animate ng-show?

Tags:

angularjs

I would like to fade out a UL on ng-show=false. I add this css:

ul {
    -webkit-transition: all 2s;
    transition: all 2s;
}

.ng-show-remove,
.ng-show-add,
.ng-hide-remove,
.ng-hide-add {
    display:block!important;
}

ul.ng-hide {
    opacity: .2;
}

But when ng-show is set to false it just instantly disappears. How do I get it to fade out instead of instantly disappearing?

Click one of the li in this fiddle for a demonstration.

like image 486
user1873073 Avatar asked Mar 10 '14 18:03

user1873073


People also ask

What is Ng animate module?

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.

How to use ng show in AngularJS?

The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.

How do I disable ng animation?

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. Simply add the ng-animate-disabled class to any elements you want to be ignored by ng-animate.

How to hide and show div in AngularJS?

Just get rid of the display: none; from your CSS. AngularJS is in control of showing/hiding that div. If you want to hide it by default, just set the value of scope. myvalue to false initially - which you're already doing.


1 Answers

I've attached a fiddle solution.

A few things to note:

The angular version you included in your fiddle doesn't support the css animations. You'll need to update to the 1.2 version (which also requires you to include the angular-animate.js file and the ngAnimate module into your app)

var app = angular.module('foo', ['ngAnimate']);

Fiddle.

like image 154
user1133128 Avatar answered Oct 02 '22 11:10

user1133128