如何拥有 2+盒子滑下来
我一直在阅读来自几个不同地方的教程,例如 http://css-tricks.com/scrollfollow-sidebar / 或 http://jqueryfordesigners.com/fixed-floating-elements/ 并一直在摆弄它们,但似乎无法弄清楚我如何能够添加更多内容,而不仅仅是页面上的一个滑动框。有什么想法吗?
I have been reading tutorials from several different places like http://css-tricks.com/scrollfollow-sidebar/ or http://jqueryfordesigners.com/fixed-floating-elements/
and have been playing around with them but cant seem to figure out how I would be able to add more then just that one sliding box on the page. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的假设(来自第一个示例链接)是,您不只是让
#sidebar
留在视图中,而是希望另一个元素也随窗口滚动(即登录用户的详细信息)。最简单的方法是将此信息添加到现有的滚动元素中:
但是,如果您想使用窗口滚动两个元素:
只需在
$(window 内对它们的两个 margin-top 进行动画处理即可).scroll()
事件处理程序:编辑
以下代码滚动
#sidebar
直到滚动达到 2000px,此时停止并滚动# user-details
直到滚动达到 4000px:您可以在此处查看它的实际效果 。
My assumption (from the first example link) is that instead of just having
#sidebar
stay in view, you want to have another element scroll with the window as well (i.e. logged in user's details).The easiest way would be to add this information to your existing scrolling element:
However, if you want to scroll two elements with the window:
It would just be a matter of animating both of their margin-top's inside the
$(window).scroll()
event handler:Edit
The following code scrolls
#sidebar
until it reaches 2000px of scroll at which point it stops and scrolls#user-details
until it reaches 4000px of scroll:You can see it in action here.