javascript - Animation angularjs not working -
i'm trying animate div on click. when click on link div should appear , div clicked disappear. made example here:
http://plnkr.co/edit/703244uj0hcg9gjkojoz?p=preview
by way code:
<a class="" ng-click="showdetails" ng-if="!showdetails"> expand </a> <div class="animate-if" ng-if="showdetails"> details!! <a style="cursor:pointer;" ng-click="!showdetails"> close </a> </div> {{showdetails}} </body> angular
var app = angular.module('plunker', ['nganimate']); app.controller('mainctrl', function($scope, $window) { showdetails = false; }); css:
.animate-if.ng-enter, .animate-if.ng-leave { -webkit-transition: 1s linear all; -moz-transition: 1s linear all; -ms-transition: 1s linear all; -o-transition: 1s linear all; transition: 1s linear all; } .animate-if.ng-enter { max-height: 0; opacity: 0; } .animate-if.ng-enter.ng-enter-active { max-height: 999px; opacity:1; } .animate-if.ng-leave { max-height: 999px; opacity:1; } .animate-if.ng-leave.ng-leave-active { max-height: 0; opacity:1; } so, when click "expand" should appear div class: animate-if , disappear one:
<a class="" ng-click="showdetails" ng-if="!showdetails"> expand </a> then, when click close should disappear div : animate-if , re-appear link "expand" again. of course using animation. not working. not appears or disappears.
you need toggle function toggle value of showdetail variable on click expand div.
js :
var app = angular.module('plunker', ['nganimate']); app.controller('mainctrl', function($scope, $window) { $scope.showdetails = false; $scope.toggledetails =function (){ $scope.showdetails = !$scope.showdetails; } }); html :
<body ng-controller="mainctrl"> <a class="" ng-if="!showdetails" ng-click="toggledetails()"> expand </a> <div class="animate-if" ng-if="showdetails"> details!! <a style="cursor:pointer;" ng-click="toggledetails()"> close </a> </div> {{showdetails}} </body>
Comments
Post a Comment