如何让元素在页面上随你滚动?
我想在网站上创建一个当您向下滚动窗口时滚动的元素。在大多数情况下,我知道这可以通过使用固定定位的一些基本 CSS 轻松解决。问题是,我不希望它始终位于屏幕上的同一空间。我希望它成为一个侧边栏元素,从其余内容开始,然后在您向下滚动页面时随您移动。有关示例,请参阅 http://www.demonoid.com/(请参阅右侧的广告)页面)。我知道可能有一个相当简单的 css 或 jquery 解决方案,但我一直想不出一个。我很感激你的帮助。
谢谢!
I would like to create an element on a website that scrolls as you scroll down the window. In most cases, I know this could easily be solved with some basic css using fixed positioning. The issue is, I would not like it to be in the same space on the screen at all times. I would like it to be a sidebar element that starts with the rest of the content, but then moves with you as you scroll down the page. See http://www.demonoid.com/ for an example (see the ad on the right side of the page). I know there is probably a fairly easy css or jquery solution, but I have not been able to think of one. I appreciate the help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个使用 jQuery 创建固定浮动元素的非常棒的教程:
固定浮动元素 |面向设计师的 jQuery
Here's a really great tutorial to create fixed-floating elements using jQuery:
Fixed Floating Elements | jQuery for Designers
也许只是一个
Maybe just a
这是一种制作方法。
使用
position:sticky
使元素浮动。这里是文章的解释。
http://updates.html5rocks.com /2012/08/Stick-your-landings-position-sticky-lands-in-WebKit
粘性位置演示
Here is a way to make it.
use
position:sticky
to get element floating.Here is the article explained.
http://updates.html5rocks.com/2012/08/Stick-your-landings-position-sticky-lands-in-WebKit
sticky position demo