滚动离开网页顶部后对 div 进行动画处理
我目前正在尝试在用户滚动离开页面顶部后,使一个 div 从另一个 div 后面出现。
我希望使用 animate 来做到这一点,以便它滑出。像这样...
但我不能弄清楚如何使红色框留在蓝色框后面,直到用户滚动离开页面顶部。
当用户滚动回到页面顶部时,我还需要反转这一点,因此红色框再次滑回蓝色框下方。
有人可以帮我吗?
I'm currently trying to make a div appear from behind another div after the user scrolls away from the top of the page.
I'm hoping to do this using animate so that it slides out. Like this...
But I can't figure out how to make the red box stay behind the blue box until the user scrolls away from the top of the page.
I also need to reverse this when the user scrolls back up to the top of the page, so the red box slides back under the blue box again.
Can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这不是最优雅的解决方案,但它仍然有效。
http://jsfiddle.net/37LZ5/
组件:
This is not the most elegant solution, but it works nonetheless.
http://jsfiddle.net/37LZ5/
Components:
我想您正在寻找这个,看看这个演示
工作演示
代码
I think you are looking for this take a look at this demo
Working demo
Code
如果我对你的问题的理解是正确的,这就是你正在寻找的东西,
因为你说,“用户从页面顶部滚动”,我在页面顶部添加了一个 div 。
这是 jsfiddle 版本
http://jsfiddle.net/xaYTt/103/
If my understanding about your question is correct, this is what you are looking for
Since you said, "User scrolls away from the top of the page", I added a div to be at the top of the page.
Here is the jsfiddle version
http://jsfiddle.net/xaYTt/103/
如果我正确理解你的问题,我用 jsFiddle 做了一些事情,这可能就是你想要的。
基本上,当您将窗口滚动超过蓝色框的距离时,红色框就会产生动画。
不是 100%,只是一个快速模型,看看这是否是您想要的。
(滚动时,单击滚动条箭头以获得更准确的结果)
此处演示:http://jsfiddle .net/peduarte/xaYTt/104/
I did something with jsFiddle that might be what you are after, if I understood your question correctly.
Basically, the red box will animate when you scroll the window more than the distance of the blue box.
Not 100%, just a quick mock up to see if that's what you want.
(When you scroll, click on the scroll bar arrows for more accurate results)
Demo here: http://jsfiddle.net/peduarte/xaYTt/104/