angular.js - AngularJS 让Div自动滚动至底部。
PHPz
PHPz 2017-05-15 17:00:33
[AngularJS讨论组]

用AngularJs做即时通讯,需要将p的滚动条固定到底部。
现在尝试了下面的做法,没有反应。

//----p滚动条置底
$scope.scrollWindow=function(){
    var _el = document.getElementById('chat_history');
    _el.scrollTop = _el.scrollHeight;
};

//----使用方法
$timeout(function(){
    $scope.scrollWindow();
},500);
PHPz
PHPz

学习是最好的投资!

全部回复(2)
给我你的怀抱

已经实践成功的答案。采用了 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());
    });
};
阿神
$scope.scrollWindow=function(){
    var _el = document.getElementById('chat_history');
    _el.scrollTop = _el.scrollHeight - _el.height;
};
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号