search

Home  >  Q&A  >  body text

angular.js - AngularJS makes Div automatically scroll to the bottom.

When using AngularJs for instant messaging, you need to fix the scroll bar of p to the bottom.
I tried the following method now, but no response.

1

2

3

4

5

6

7

8

9

10

<code>//----p滚动条置底

$scope.scrollWindow=function(){

    var _el = document.getElementById('chat_history');

    _el.scrollTop = _el.scrollHeight;

};

 

//----使用方法

$timeout(function(){

    $scope.scrollWindow();

},500);</code>

PHPzPHPz2904 days ago705

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.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

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

        });

    };</code>

    reply
    0
  • 阿神

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

    1

    2

    3

    4

    <code>$scope.scrollWindow=function(){

        var _el = document.getElementById('chat_history');

        _el.scrollTop = _el.scrollHeight - _el.height;

    };</code>

    reply
    0
  • Cancelreply