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
Release: 2016-05-16 17:05:42
Original
1295 people have browsed it

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);
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template