如何在不滚动整个页面的情况下自动滚动内联div? [英] How to automatic scroll inline div without scrolling the whole page?
问题描述
我有一个 div
作为文件视图的容器。 div
已滚动到 y
方向。
I希望在加载页面时自动将此容器内的内容 div
滚动到特定位置,但不滚动整个页面。我尝试了< a name =scrollHere>
和 location.hash ='scrollHere';
但这滚动整个页面。
您有什么想法吗?
在容器元素上使用scrollTop,并根据容器内元素的y位置计算出一个值。
$ b Mozilla Element.scrollTop
$ b 堆栈溢出:javascript-textarea-scrolltop
I have a div
as a container for a file view. This div
has scrolling in y
direction.
I want to automatically scroll the content inside this container div
to a specific position when loading the page, but without to scroll the whole page. I have tried with <a name="scrollHere">
and location.hash = 'scrollHere';
but this scrolls the whole page.
Do you have any ideas?
Use scrollTop on the container element with a value calculated from the y position of the element inside the container.
stackoverflow: javascript-textarea-scrolltop
这篇关于如何在不滚动整个页面的情况下自动滚动内联div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!