search

Home  >  Q&A  >  body text

angular.js - AngularJS 让Div自动滚动至底部。

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

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

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

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-15 17:02:33

    Answers that have been successfully implemented. HTML5 的API DOMNodeInserted is used to detect changes in element content.

    $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());
        });
    };

    reply
    0
  • 阿神

    阿神2017-05-15 17:02:33

    $scope.scrollWindow=function(){
        var _el = document.getElementById('chat_history');
        _el.scrollTop = _el.scrollHeight - _el.height;
    };

    reply
    0
  • Cancelreply