粘性 Div 停止于底部
我有一个粘性 div,但我需要它停在底部的某个点。当然,在示例(下面的链接)中它永远不会到达底部,但如果我有一个宽度较大的 div,我希望它在到达页脚之前停止。如果您不明白这个问题,请告诉我,帮助会很大。
http://blog.yjl.im/2010 /01/stick-div-at-top-after-scrolling.html
I have a sticky div but I need it to stop at a certain point toward the bottom. Sure in the example (link below) it never hits bottom, but if I have a div with a bigger width I want it to stop before it hits my footer. Let me know if you don't understand the question, help would be great.
http://blog.yjl.im/2010/01/stick-div-at-top-after-scrolling.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一个 jquery 插件可以为你解决这个问题。该插件会将元素固定到页面顶部,如示例中所示;并且,如果您将可选限制设置为要停止的元素的顶部,则它应该在滚动时向上移动页面。您必须将“固定”元素的高度添加到限制,以使其在触及您不希望其触及的元素之前再次向上移动页面,如果需要,还可以加上一些边距。
这是一个演示这一点的小提琴: http://jsfiddle.net/ZczEt/2/
这里是插件及其来源:https://github.com/bigspotteddog/ScrollToFixed
我忘了提及,这个插件在修复后还将修复粘性标题下方内容中的问题。在您的示例中,如果您缓慢滚动,您会注意到当标题固定时,内容会跳跃标题的高度。这个插件弥补了这一点。
Here is a jquery plugin that may solve this for you. This plugin will fix the element to the top of the page, as you have in your example; and, if you set the optional limit to the top of the element you want to stop at, it should move up the page as it is scrolled. You will have to add the height of the "fixed" element to the limit to get it to move up the page again before it touches the element you do not want it to touch, plus some margin if desired.
Here is a fiddle that demonstrates this: http://jsfiddle.net/ZczEt/2/
Here is the plugin and its source: https://github.com/bigspotteddog/ScrollToFixed
I forgot to mention, this plugin will also fix that hitch in the content below your sticky header when it goes fixed. In your example, if you scroll slowly, you will notice that the content jumps the height of the header when it becomes fixed. This plugin compensates for that.
这与示例有点不同,但我认为这符合您的要求:
请参阅此 jsFiddle更多详细信息示例
It's a bit of a departure from the example, but I think this does what you're after:
See this jsFiddle Example for more details
我已经使用 jquery 插件
停在底部:
i have used jquery plugin
to stop at bottom: