Home >Web Front-end >JS Tutorial >The newly added content is how to automatically move the scrollbar of the div to the bottom_javascript skills

The newly added content is how to automatically move the scrollbar of the div to the bottom_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:05:421291browse

Sometimes when we make dynamically growing divs, we usually append the content to the bottom of the div, but this will bring about a rather painful problem, that is, the newly added content will be hidden at the bottom, like this
The newly added content is how to automatically move the scrollbar of the div to the bottom_javascript skills
How to make the scrollbar automatically move to the bottom? This requires the help of js. Assume that the id of the div is myDiv, then use the native js to implement the following:

Copy code The code is as follows:

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

If you use jquery, it is also very simple
Copy code The code is as follows:

var $div = $('#myDiv');
$div.scrollTop($div[0].scrollHeight);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn