angular.js - AngularJS 让Div自动滚动至底部。
本文介绍了angular.js - AngularJS 让Div自动滚动至底部。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
用AngularJs做即时通讯,需要将div的滚动条固定到底部。
现在尝试了下面的做法,没有反应。
//----DIV滚动条置底
$scope.scrollWindow=function(){
var _el = document.getElementById('chat_history');
_el.scrollTop = _el.scrollHeight;
};
//----使用方法
$timeout(function(){
$scope.scrollWindow();
},500);
解决方案
已经实践成功的答案。采用了 HTML5
的API DOMNodeInserted
来检测元素内容的变动。
$scope.scroll_go=function(){
var _childEl=jQuery(".chat-history"),_el=jQuery("#chat_history");
if(_childEl.height()>(_documentSize.height - 50)){
_el.scrollTop(_childEl.height());
}
//----检测元素内容变动
_childEl.bind('DOMNodeInserted',function(){
_el.scrollTop(_childEl.height());
});
};
这篇关于angular.js - AngularJS 让Div自动滚动至底部。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文