javascript - Having a two directions animation swap using ng-animation-swap -


i have sort of slider (but more ppt in fact, , depending on button click outcome have different).

i use ng-animate-swap efficiently change current displayed slide, , works when going in 1 way. problem when try go other way, change animation class, soon-to-be previous slide, animation still 1 of state before... can find working example here inspired ng-animate-swap doc: http://plnkr.co/edit/darf1w7em7znur7myx3o?p=preview

as can see problem change on css class applied new slide, , not 1 removed.

you can find relevant code below :

index.html :

<body ng-app="nganimateswapexample">   <div ng-controller="appctrl">      <div class="container">        <div ng-animate-swap="number" class="cell {{swapanimation}}" ng-class="colorclass(number)">          {{ number }}        </div>     </div>     <a ng-click="previousnumber()">previous</a>     <a ng-click="nextnumber()">next</a>   </div> </body> 

script.js :

.controller('appctrl', ['$scope',function($scope) { $scope.number = 0;  var colors = ['red','blue','green','yellow','orange']; $scope.colorclass = function(number) {   return colors[number % colors.length]; };  $scope.nextnumber = function(){   $scope.swapanimation = "swap-animation";   $scope.number += 1; };  $scope.previousnumber = function(){   $scope.swapanimation = "swap-animation-reverse";   $scope.number -= 1; };   }]); 

animations.css :

.container {    height:250px;    width:250px;    position:relative;    overflow:hidden;    border:2px solid black;  } .container .cell {    font-size:150px;    text-align:center;    line-height:250px;    position:absolute;    top:0;    left:0;    right:0;    border-bottom:2px solid black; } .swap-animation.ng-enter, .swap-animation.ng-leave {    transition:0.5s linear all;  }  .swap-animation.ng-enter {    top:-250px;  }  .swap-animation.ng-enter-active {    top:0px;  }  .swap-animation.ng-leave {    top:0px;  }  .swap-animation.ng-leave-active {    top:250px;  }    .swap-animation-reverse.ng-enter, .swap-animation-reverse.ng-leave {    transition:0.5s linear all;  }   .swap-animation-reverse.ng-enter {    top:250px;  }  .swap-animation-reverse.ng-enter-active {    top:0px;  }  .swap-animation-reverse.ng-leave {    top:0px;  }  .swap-animation-reverse.ng-leave-active {    top:-250px;  } 

simply add timeout after changed cssclass in nextnumber() , previousnumber() logic, in first cycle element change class , in next cycle ng-animate-swap executes animation.

$scope.nextnumber = function(){   $scope.swapanimation = "swap-animation";   $timeout(function(){     $scope.number += 1;   }); };  $scope.previousnumber = function(){   $scope.swapanimation = "swap-animation-reverse";   $timeout(function(){     $scope.number -= 1;   }); }; 

http://plnkr.co/edit/yedmewrgxiranalqf20u?p=preview


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -