代码描述:js实现滚动条 处于最下端。js实现滚动条处于最下端代码下载
现在就以div作为例子,当div的内容超出尺寸时,一般要设置一个滚动条,这样拖动滚动条就可以查看全部内容了,但是如果我们动态的像div中添加内容的时候,滚动条始终处于最上端,新增加的内容被隐藏了,下面介绍一下如何解决此问题。 代码如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> #box { height:300px; width:500px; background-color:red; overflow:scroll; } #inner { width:200px; height:400px; margin:0px auto; background-color:blue; } </style> <script type="text/javascript"> window.onload=function() { var box=document.getElementById("box"); var newDiv=document.createElement("div"); newDiv.style.width="200px"; newDiv.style.height="100px"; newDiv.style.backgroundColor="green"; box.appendChild(newDiv); box.scrollTop = box.scrollHeight; } </script> </head> <body> <div id="box"> <div id="inner"></div> </div> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能