Home > Web Front-end > JS Tutorial > body text

How to use js to control the scroll bar of a div so that it automatically scrolls to the bottom when the content is updated

高洛峰
Release: 2016-12-08 16:06:44
Original
1330 people have browsed it

As shown below:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
 
<script type="text/javascript">
function add()
{
var now = new Date();
var div = document.getElementById(&#39;scrolldIV&#39;);
div.innerHTML = div.innerHTML + &#39;time_&#39; + now.getTime() + &#39;<br />&#39;;
div.scrollTop = div.scrollHeight;
}
</script>
<div id="scrolldIV" style="overflow:auto; height: 100px; width: 400px; border: 1px solid #999;">
</div>
<input type="button" value="插入一行" onclick="add();">
用js控件div的滚动条,让它在内容更新时自动滚到底部</body>
</html>
Copy after login


Related labels:
js
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