javascript - AngularJS: CSS Animation On Click (ngClick) -
i've seen several questions related css animations 'on click' in angular when researching this, without solid or definitive answers.
i want know best practice way achieve css animation when clicking on element in angularjs environment (1.x). specifically, lets want utilize animation animate.css , each time click on element in question animation should happen.
here route have taken currently, wonder if there might better way:
markup:
<div class="play" ng-click="animate($event)"></div> js function (in controller):
$scope.animate = function(event) { var el = event.srcelement; angular.element(el).addclass('animate'); $timeout(function() { angular.element(el).removeclass('animate'); }, 1000); }; css:
.play.animate { animation:0.5s bouncein ease; } i don't particularly love use of timeout here remove class after animation should complete. ngclick answer here, or should using totally custom directive?
you can set variable in controller:
this.animated = false; this.animationtoggle = function(){ this.animated = !this.animated; }; and inside element change value on click , conditionaly add class:
<div ng-class="{'play' : ctrl.animated}" ng-click="ctrl.animationtoggle()"></div>
Comments
Post a Comment