2017-03-05 47 views
0

In this plunk我有一个ngTable四行。当用户点击桌子下面的按钮时,我需要第二行的背景颜色(不是文本)淡入淡出。该行在淡入时变为着色,但是在两秒钟后,背景颜色突然消失而不是消失。任何想法如何解决这一问题?为ngTable添加效果

CSS

.select { 
    transition: 1s linear all; 
    opacity: 1; 
} 

.select.ng-hide { 
    transition: 1s linear all; 
    opacity: 0; 
} 

HTML

<table ng-table="tableParams" class="table table-bordered table-hover"> 
     <tbody> 
      <tr ng-repeat="u in data" ng-class="{ 'select': u.select}"> 
       <td title="'User ID'" style="width:150px">{{ u.uid }}</td> 
       <td title="'Name'" style="width:150px">{{ u.nm }}</td> 
       <td title="'Group'" style="width:200px">{{ u.ugr }}</td> 
      </tr> 
     </tbody> 
    </table> 
    <br> 
    <button ng-click="selectRow()">Color second line and fade</button> 

的Javascript

var app = angular.module('app', ['ngTable']); 

app.controller('myCtl', function($scope,$timeout,NgTableParams) { 


    $scope.data = [ 
     { uid: 'User 11', nm: 'Name 11', ugr: 'Group 1'}, 
     { uid: 'User 12', nm: 'Name 12', ugr: 'Group 1'}, 
     { uid: 'User 21', nm: 'Name 21', ugr: 'Group 1'}, 
     { uid: 'User 22', nm: 'Name 22', ugr: 'Group 1'} 
    ]; 

    $scope.tableParams = new NgTableParams({dataset: $scope.data}); 

    $scope.selectRow = function(){ 
     $scope.data[1].select = true; 
     $timeout(function(){ 
      $scope.data[1].select = false; 
     },2000); 
    }; 

}); 
+0

期望是什么?你想淡出缓慢? – Aravind

+0

是的,背景颜色应该淡入淡出 – ps0604

回答

2

您可以添加其他的CSS不选行

.unselect { 
    background-color: transparent; 
    transition: 1s linear all; 

} 

然后把三元运营商在NG-类

ng-class="{true: 'select', false: 'unselect'}[u.select]" 

Working Plunkr

1

你必须有自己的风格,如下,

.select { 

    -webkit-transition: opacity 2s; /* For Safari 3.1 to 6.0 */ 
    transition: opacity 2s; 
    opacity: 0.5; 
} 

.select.ng-hide { 

    -webkit-transition: opacity 2s; /* For Safari 3.1 to 6.0 */ 
    transition: opacity 2s; 
    opacity: 0; 
} 

原因:要在Chrome中看到您需要

  1. -webkit-过渡
  2. 你有opacity:1的。选择这改变下一秒当发生超时的不透明度。

UPDATED PLUNK

+0

这与背景一起工作,但文字在淡出时消失,不应该。 – ps0604

+0

对不起,但现在背景只是出现和消失,没有淡入或淡出。 – ps0604

+0

让我们继续[讨论聊天](http://chat.stackoverflow.com/rooms/137274/adding-effect-to-ngtable) – Aravind