AngularJS 动画元素消失

AngularJS animate element disappearing

在下面的例子中你可以看到,当项目被添加到列表中时,它正在做淡入淡出的动画然后消失,我希望它在动画之后有 bootstrap 样式,这可能与 bootstrap css 但我无法弄清楚 css 代码到底在做什么。

代码

plunkr.co

html

  <head>
    <link rel="stylesheet" href="https://bootswatch.com/lumen/bootstrap.min.css">
    <link rel="stylesheet" href="style.css"/>
    <script src="https://code.angularjs.org/1.5.0-rc.0/angular.js"></script>
    <script src="https://raw.githubusercontent.com/angular/bower-angular-animate/master/angular-animate.min.js"></script>

    <script src="script.js"></script>
  </head>

  <body>
    <div ng-controller="Controller">
    <input type="button" value='click' ng-click="addItem()"/>
    <input type="button" value="delete" ng-click="deleteItem()"/>
    <input type="text" ng-model="filterText"/>
    <table class="table table-striped table-hover center-table">
      <tr class="fade" ng-repeat="item in (filtered=(items | filter:filterText))">
        <td>{{item.name}}</td>
      </tr>
    </table>
    </div>
  </body>

</html>

js

    var app=angular.module('App',['ngAnimate']);
app.controller('Controller',function($scope){
  $scope.items=[];

  $scope.addItem=function(){
    $scope.items.push({'name':'cgagaga'})
  };
  $scope.deleteItem=function(){
    $scope.items.splice(0,1);
  }
});

css

.fade.ng-enter {
    transition: 2s linear all;
    background-color: lightgreen;
    opacity: 1;
}

/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active {
    background-color: #f3f3f3;
    opacity: 1;
}

.fade.ng-leave {
    transition: 1s linear all;
    background-color: #FF6F79;
    opacity: 1;
}

.fade.ng-leave.ng-leave-active {
    opacity: 0;

将淡入淡出动画的名称更改为其他名称(例如 fade1),并将 .fade1.ng-enter 中的不透明度更改为 0。

.fade1.ng-enter {
   transition: 2s linear all;
    background-color: lightgreen;
    opacity: 0;
}

.fade1.ng-enter.ng-enter-active {
    background-color: #f3f3f3;
    opacity: 1;
}

.fade1.ng-leave {
    transition: 1s linear all;
    background-color: #FF6F79;
    opacity: 1;
}

.fade1.ng-leave.ng-leave-active {
    opacity: 0;
}