问题背景:
固定宽度和高度的div层,当div里的内容在超出固定的高度之后,即产生了溢出,如何保证滚动条实时自动同步滚动到最底部?
解决方案:
Demo#tips{
width:350px;
height:580px;
color:red;
font-size:18px;
border:5px solid red;
word-break:break-all;
padding:5px;
overflow-y:scroll;
}
$().ready(function(){
var msg = "欢迎访问金牛座技术博客:http://www.blogdaren.com
";
$("#tips").empty();
setInterval(function(){
$("#tips").append(msg);
var tipsDiv = document.getElementById("tips");
tipsDiv.scrollTop = tipsDiv.scrollHeight;
}, 300);
})
效果图预览: