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

标签 javascript css angularjs html

我想知道在下面的示例中如何将背景颜色添加到新添加的行中。添加新行时,滚动条会向下滚动,但如何通过向该行添加背景色来突出显示它。任何帮助都会很棒。这是 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/

相关文章:

javascript - jQuery anchor preventDefault

javascript - html css jquery modal 无法在浏览器中打开

javascript - 是否可以在 css 中按下并按住按钮触发事件?

javascript - AngularJS - 未知提供商 : AuthProvider

html - 对齐两个垂直的 HTML 表格

javascript - TypeError : Value undefined (result of expression xmlDoc. 加载)不是对象

javascript - Jquery 同位素插件 : Custom layout mode: Category rows - how to add a header to each category row

javascript - Mongo 为具有唯一 : false 的字段提供 dup key 错误

html - 移动版 chrome 顶部栏的颜色

angularjs - Karma 测试运行器和闭包库 "NOT SERVED FILE"