如何在不滚动整个页面的情况下自动滚动内联div? [英] How to automatic scroll inline div without scrolling the whole page?

查看:219
本文介绍了如何在不滚动整个页面的情况下自动滚动内联div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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.

Mozilla Element.scrollTop

stackoverflow: javascript-textarea-scrolltop

这篇关于如何在不滚动整个页面的情况下自动滚动内联div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆