[英]How to scroll to bottom of div generated by ng-repeat Angular JS using JQuery?
[英]how to scroll bottom of div using angular js
我有一个div我在其中添加了元素。我想在div中添加元素时滚动到div的底部。我知道如何在jquery中执行。但我不知道如何使用jquery Scroll使用angular js 滚动div的底部?
testCaseContainer是div的id。
var elem = document.getElementById('testCaseContainer'); // just to
// scroll down
// the line
elem.scrollTop = elem.scrollHeight;
我想知道如何使用角度?
http://plnkr.co/edit/M8tCL8Szc3h3FatFLycG?p=preview
我在div容器中添加了css以便滚动。
.heightClass{
height:100px;
overflow :auto;
}
如何在添加项目时将焦点移动到下方..请发布您的答案..
您可以创建自己的滚动指令来监视集合,当它发生更改时,设置滚动位置:
app.directive('scroll', function($timeout) {
return {
restrict: 'A',
link: function(scope, element, attr) {
scope.$watchCollection(attr.scroll, function(newVal) {
$timeout(function() {
element[0].scrollTop = element[0].scrollHeight;
});
});
}
}
});
HTML
<div class="heightClass" scroll="studentDetail">
注意:需要$ timeout以确保在呈现视图后设置滚动位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.