[英]how to scroll bottom of div using angular js
I have a div in which I added element .I want to scroll to bottom of the div whenever element added in div.I know how to do in in jquery .But I did not know how to scroll using angular js I know using jquery Scroll to bottom of div? 我有一个div我在其中添加了元素。我想在div中添加元素时滚动到div的底部。我知道如何在jquery中执行。但我不知道如何使用jquery Scroll使用angular js 滚动div的底部?
testCaseContainer is id of div . testCaseContainer是div的id。
var elem = document.getElementById('testCaseContainer'); // just to
// scroll down
// the line
elem.scrollTop = elem.scrollHeight;
I want to know how it is possible using angular ? 我想知道如何使用角度?
http://plnkr.co/edit/M8tCL8Szc3h3FatFLycG?p=preview http://plnkr.co/edit/M8tCL8Szc3h3FatFLycG?p=preview
I added css in div container so that it scroll . 我在div容器中添加了css以便滚动。
.heightClass{
height:100px;
overflow :auto;
}
how to move focus below when item is added ..please post your answer.. 如何在添加项目时将焦点移动到下方..请发布您的答案..
You could create your own scroll directive that watches a collection, and when it changes, sets the scroll position: 您可以创建自己的滚动指令来监视集合,当它发生更改时,设置滚动位置:
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 HTML
<div class="heightClass" scroll="studentDetail">
Note: $timeout is needed to ensure that the scroll position is set after the view is rendered. 注意:需要$ timeout以确保在呈现视图后设置滚动位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.