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.
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 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.
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.
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.
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.
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