滚动回div的顶部 [英] Scroll back to the top of div
本文介绍了滚动回div的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< div id =containerDiv>< / div>
#containerDiv {
位置:绝对;
top:0px;
width:400px;
身高:100%;
padding:5px;
font-size:.875em;
overflow-y:scroll;
}
document.getElementById(containerDiv)。innerHTML = variableLongText;
如何在下一次将滚动位置重置回容器div的顶部?
解决方案
var myDiv = document.getElementById('containerDiv');
myDiv.innerHTML = variableLongText;
myDiv.scrollTop = 0;
请参阅 scrollTop
属性。
<div id="containerDiv"></div>
#containerDiv {
position: absolute;
top: 0px;
width: 400px;
height: 100%;
padding: 5px;
font-size: .875em;
overflow-y: scroll;
}
document.getElementById("containerDiv").innerHTML = variableLongText;
How to reset the scroll position back to top of container div the next time?
解决方案
var myDiv = document.getElementById('containerDiv');
myDiv.innerHTML = variableLongText;
myDiv.scrollTop = 0;
See the scrollTop
attribute.
这篇关于滚动回div的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文