繁体   English   中英

如何让div自动滚动到底部?

[英]How would I make a div automatically scroll to the bottom?

我希望我的div在添加段落时自动保持在底部,我该怎么做? 这是我的代码:

http://pastebin.com/wespDUXp

你去了: http//jsfiddle.net/tMnvJ/

只需将JavaScript代码放在一个函数中,然后通过添加内容的任何进程调用它。 像这样......

function addParagraph()
{
    //do you add paragraph stuff...
    //then call this line to scroll to the bottom of your div
    document.getElementById('myDiv').scrollTop = document.getElementById('myDiv').scrollHeight;
}

希望有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM