向具有位置的元素添加边界:固定
我有一个 position:fixed
的 div,它可以正确地随着滚动移动,但我希望它在到达某些(y 轴)边界时停止。这样做的方法是什么?
理想情况下,该解决方案不会闪烁并且性能良好。 Twitter 的右侧面板很接近我想要的。
I've got a div with position: fixed
that moves with the scroll properly, but I'd like to have it stop when it reaches certain (y-axis) boundaries. What's the method to go about doing this?
Ideally the solution doesn't flicker and is performant. Twitter's right panel is close to what I'd like.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 http://jsbin.com/ijexe 的更实用的版本
(更新了代码以重新启用原始位置...本质上,一旦它到达原始顶部位置,它将再次开始滚动)
您可以更新 http://jsbin.com/ijexe 代码只需将 jquery 函数替换为下面的函数即可进行测试...
只需
在示例中:(
确保您的位置:absolute & top :值集)
更新的功能(放置在结束正文标记之前)
您可以更新:
scrollTo - 从屏幕顶部开始/停止元素滚动的偏移量
* 只需确保将滚动到设置为与样式表声明相同的值...
scrollClass - 的类名称将函数应用到的元素
This is a more functional vetrsion of http://jsbin.com/ijexe
(updated the code to reenable the origional position... essentially once it hits its origional top position it will start scrolling again)
You can update the http://jsbin.com/ijexe code to test simply by swapping out the jquery function with the one below...
In the
in the example:
(just make sure you have your position:absolute & top: value set)
Updated function (place before the closing body tag)
You can update:
scrollTo - The offset from the top of the screen to start/stop the element scrolling
* Just make sure scroll to is set to the same value as your stylesheet decliration...
scrollClass - The class name for the element(s) to apply the function to