gpt4 book ai didi

javascript - 如何为新添加的行添加背景颜色angularjs

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:20 25 4
gpt4 key购买 nike

我想知道在下面的示例中如何将背景颜色添加到新添加的行中。添加新行时,滚动条会向下滚动,但如何通过向该行添加背景色来突出显示它。任何帮助都会很棒。这是 fiddle - http://jsfiddle.net/cpfx07qq/

html - 
<div ng-app="myApp" ng-controller="MyCtrl">
<button ng-click="add()" scroll-bottom="bottom">Add</button>
<ul id="bottom">
<li ng-repeat="item in list">{{item}}</li>
</ul>
</div>

最佳答案

试试这个:

<div ng-app="myApp" ng-controller="MyCtrl">
<button ng-click="add()" scroll-bottom="bottom">Add</button>
<ul id="bottom">
<li ng-repeat="item in list" ng-class="{last: $last && isNew }">{{item}}</li>
</ul>
</div>

controller 中:

function MyCtrl($scope) {
$scope.isNew = false;
$scope.list = ["item 1", "item 2", "item 3", "item 4", "item 5"];
$scope.add = function() {
$scope.isNew = true;
$scope.list.push("new item");
}
}

css 中:

.last {
background-color: red;
}

关于javascript - 如何为新添加的行添加背景颜色angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41529781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com