简体   繁体   English

滚动后从文档顶部停止div 100px

[英]Stop a div 100px from top of document after scroll

I am having random results with window scrolling. 我在窗口滚动中得到随机结果。 I basically click on a box, open it and it expands. 我基本上单击一个框,将其打开,然后展开。 Once expanded, the window should scroll to it, stopping it 100px from the top of the browser window, but it doesn't and it's a bit random, not all boxes stops at the same distance form the window. 展开后,窗口应滚动到该窗口,并从浏览器窗口顶部停止100px,但它不是,并且有点随机,并非所有框都与窗口距离相同。

This is what i mean i'm working on, expand the box and see: Thanks 这就是我正在处理的意思,请展开方框并查看:谢谢

$('html, body').animate({scrollTop:$(".opened").position().top - 100}, 2000);

Use position() over offset() . 使用position()超过offset()

http://api.jquery.com/position/ http://api.jquery.com/position/

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

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