在<div> </div>上设置默认滚动点

时间:2013-07-19 21:25:36

标签: css html scroll scrollview

我有

.scroller {
    font-family : Arial,Sans-Serif;
    background : white;
    overflow-y : scroll;
    font-size  : 9.5pt; /* needed for scrollers w/o tables */
    }   

我后来申请

<div class="scroller">
   ... lots of content here ...
</div>

默认情况下,会显示滚动条中内容的顶部。我想滑到中间的东西。

1 个答案:

答案 0 :(得分:0)

假设您的内容是这样的:

<div class="scroller">
   <div id="1">
      ... lots of content here ...
   </div>
   <div id="2">
      ... lots of content here ...
   </div>
</div>

使用此按钮滚动到<div id="2">

$("div.scroller").scrollTop($("#2").offset().top);

在这里看一个例子:Fiddle Demo