Animate.css and Angularjs ng-hide
Asked Answered
S

2

8

I am learning and experimenting with Angularjs and animate.css. I am trying to add animations when the ng-show is true or false. The showing and hiding works but not the animations. Hope someone here can show me what I am doing wrong.

Here is the plunk.

thanks for the help.

Stoke answered 24/6, 2014 at 3:18 Comment(3)
I'm not sure that the newer versions of $animate will play nice with animate.css since they add/remove multiple classes during the transition... if animate.css is a requirement you might be better off with ng-class and handling figuring out which class should be applied based on a boolean that way plnkr.co/edit/LN8wunbuPrKcuEV1ouMQ?p=previewMessapian
no animate.css is not a requirement. I was just trying to figure out how they both play together. Thanks for your response and the solution you provided.Stoke
np I tried quite a few things regarding ng-class too but unfortunately couldn't get it working... would be nice to see a solution to working with animate.css, not sure why a simple ng-class using the showme property was adding/removing the classes with fadeIn and fadeOut specified as animations and using the animated class... unfortunately no real experience with animate.css so hard for me to tell what's wrong.. here's that though: plnkr.co/edit/Ey20sPZLqOCmfdFcBai7?p=previewMessapian
J
10

Here's a slightly modified version of your code with ng-show and animate.css working together.

HTML

<div ng-controller="controller">
  <button ng-click="showme = !showme">Show or Hide</button>
  <div ng-show="showme" class="boxme">
    <h2>Box to Show and Hide</h2>
    <p>Show and hide this box using animate.css the angularway!</p>
  </div>
</div>

JavaScript

(function() {
    var app = angular.module("theapp", ['ngAnimate']);
    var controller = function($scope){
        $scope.showme = false;
    };
    app.controller("controller", controller);
}());

CSS

.boxme.ng-hide-add {
    -webkit-animation: fadeOutLeftBig 0.4s;
    display: block!important;
}
.boxme.ng-hide-remove {
    -webkit-animation: fadeInLeftBig 0.4s;
}

http://jsfiddle.net/h58wsxcw/

Note the options on the left (body tag, external resources) that have to be set to get angular up and running on jsfiddle.

Jobie answered 10/10, 2014 at 15:20 Comment(0)
M
1

Found a solution that seems to work with ngAnimate and animate.css and I upgraded the version to 1.2.17 and it seems to still work using this method... not sure why I couldn't reproduce in a plunkr: http://jsbin.com/usaruce/2677/edit?html,css,js,output

Messapian answered 24/6, 2014 at 18:9 Comment(1)
Thanks. I don't understand why ng-show and ng-hide would not work with animation.css. Thanks for the help.Stoke

© 2022 - 2024 — McMap. All rights reserved.