2

如何在 ng-grid 中为新创建的行设置动画?

我想要的是当新数据从服务器进来时,它被添加到网格的开头,然后该行会发光几秒钟。

我尝试将 ng-animate 类添加到网格的 rowTemplate 中,但没有成功:

$scope.gridOptions = { 
    data: 'myData',
    rowTemplate: '<div style="height: 100%" class="reveal-animation"><div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }">&nbsp;</div><div ng-cell></div></div></div>'
};

我的显示动画(直接从 ng-animate 文档中提取)是:

.reveal-animation.ng-enter {
 -webkit-transition: 1s linear all;
 transition: 1s linear all;
 opacity: 0;
}

.reveal-animation.ng-enter.ng-enter-active {

 opacity: 1;
}

但这似乎不适用于网格。

有没有办法做到这一点?

这是我尝试的 Plunker http://plnkr.co/edit/iR9voQaFRREi0pjNLQgc?p=preview

<ul>在底部添加了一个以显示我想要的行为(并证明 ng-animate 正在工作)。

4

1 回答 1

7

对此进行动画处理的正确方法是将动画绑定到.ngRowie:

/*
 The animate class is apart of the element and the ng-enter class
 is attached to the element once the enter animation event is triggered
*/
.ngRow.ng-enter {
 -webkit-transition: 1s linear all; /* Safari/Chrome */
 transition: 1s linear all; /* All other modern browsers and IE10+ */

 /* The animation preparation code */
 opacity: 0;
}

/*
 Keep in mind that you want to combine both CSS
 classes together to avoid any CSS-specificity
 conflicts
*/
.ngRow.ng-enter.ng-enter-active {
 /* The animation code itself */
 opacity: 1;
}

问题是您正在使用 unshift 将值推送到数组的开头,但是 ng-grid 仍然通过在网格底部添加一行并重新绑定所有行来起作用,这样无意中的第一项在grid 是获取动画的那个。

这是我的叉子的 plunker,它具有上述 css 工作 - 也许你可以更进一步:http ://plnkr.co/edit/gNSM4FRMFcTtQtT6EU7b?p=preview

作为一个想法:也许您可以让元素作为正常推送进入数据集,并通过使它们保持相反顺序的方式重新排列网格。这可能会诱使网格为最新的内容设置动画,但将最新的内容保留在网格的顶部。

老实说,我发现简单地构建我自己的网格并将 ng-repeat 绑定到 ng-repeattr比尝试与其他网格系统大惊小怪要容易得多,尤其是像 ng-grid 这样你无法控制行为的网格系统。

于 2013-12-04T20:40:04.840 回答