如何在带有溢出的div上设置x和y滚动位置:滚动? [英] How to set x and y scroll position on a div with overflow: scroll?
本文介绍了如何在带有溢出的div上设置x和y滚动位置:滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有以下标记:-
.outerDiv {
width: 500px;
overflow: scroll;
}
.innerDiv {
width: 1000px;
}
<div class="outerDiv">
<div class="innerDiv">
</div>
</div>
我(很有可能使用JavaScript)如何设置该滚动条的x和y位置?
How do I (most likely with JavaScript) set the x and y position of that scroll?
推荐答案
您可以使用jQuery scrollLeft()和scrollTop()方法.
You can use jQuery scrollLeft() and scrollTop() methods.
$('.outerDiv').scrollLeft(300);
$('.outerDiv').scrollTop(50);
示例: https://jsfiddle.net/upwrrj70/
这篇关于如何在带有溢出的div上设置x和y滚动位置:滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文