The new addition is how to automatically move the scrollbar of div to the bottom

  • 2020-03-30 01:09:58
  • OfStack

Sometimes when we do dynamically growing divs, we usually put the content append at the bottom of the div, but this can lead to a very painful problem, which is that the new content will be hidden at the bottom, like this
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201401/201401021649331.gif? 201402164959 ">
How to make the scrollbar automatically move to the bottom, which needs the help of js, assume that the id of div is myDiv, then use the native js implementation as follows:

var myDiv = document.getElementById('myDiv');  
myDiv.scrollTop = myDiv.scrollHeight;

If you use jquery, it's easy

var $div = $('#myDiv');  
$div.scrollTop($div[0].scrollHeight); 

Related articles: