Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在窗口滚动时得到随机结果。我基本上点击一个框,打开它并展开。展开后,窗口应该滚动到它,在距离浏览器窗口顶部 100 像素处停止它,但它不会而且它有点随机,并非所有框都停止在与窗口相同的距离处。
这就是我的意思,我正在努力,展开盒子,看看:谢谢
$('html, body').animate({scrollTop:$(".opened").position().top - 100}, 2000);
使用position()过offset()。
position()
offset()
http://api.jquery.com/position/