简体   繁体   English

滚动到溢出包含的div:auto

[英]Scroll to a div contained in a overflow:auto

i have this: 我有这个:

<div id="parent" style="overflow:auto">
   ...
   <div id="test">Hello</div>
   ...
</div>

My question is: how to scroll parent div to have test div as first line of parent ? 我的问题是:如何滚动父div以将test div作为父的第一行?

If you don't want to use a plugin, see element.scrollIntoView : 如果您不想使用插件,请参见element.scrollIntoView

$("#test").get(0).scrollIntoView();

// Plain ol' JS:
document.getElementById("test").scrollIntoView();

If you're using jQuery (or are able to do so), take a look at the ScrollTo plugin. 如果您正在使用jQuery (或能够使用jQuery ),请查看ScrollTo插件。

From documentation 从文档

With this plugin, you will easily scroll overflowed elements, and the screen itself. 使用此插件,您可以轻松滚动溢出的元素以及屏幕本身。 It gives you access to many different options to customize and various ways to specify where to scroll. 它使您可以访问许多不同的选项以进行自定义,并可以使用多种方法指定滚动位置。

http://plugins.jquery.com/project/ScrollTo http://plugins.jquery.com/project/ScrollTo

The easiest way is to use this plugin. 最简单的方法是使用此插件。

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

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