【发布时间】:2013-04-02 20:09:14
【问题描述】:
谁能推荐一种在向下滚动页面时将滚动条捕捉到元素顶部的“最佳”方法?
例如,如果我的布局如下:
<div id="section-one" style="width: 100%; height: 600px;">
Section One
</div>
<div id="section-two" style="width: 100%; height: 600px;">
Section Two
</div>
<div id="section-three" style="width: 100%; height: 600px;">
Section Three
</div>
<div id="section-four" style="width: 100%; height: 600px;">
Section Four
</div>
如果用户正在查看第一节并开始向下浏览,第二节开始占据浏览器视口的一部分,我希望浏览器自动对齐到下一个 div 的顶部。
我对 .scroll() 和 .scrollTop 很熟悉,但有点不确定从这里往哪里走。
【问题讨论】:
-
所以你基本上希望下一个
<div>跳到屏幕顶部,只要它在视口内?它应该在那里停留多长时间(想想用户继续滚动并在片刻之后识别出内容移动到视口顶部)。如果用户的屏幕高于 600px 会发生什么,因为总会有两个<div>s 可见?