如何根据浏览器中的位置更改元素的背景
我过去见过一些非常奇特的单页网站,其中某些元素在滚动页面时会出现。据我记得,效果似乎是仅使用 css 编写的。我相信 z-index 和position 属性应该可以实现吗?
不幸的是,我再也找不到这些页面了。
有人有工作示例吗?
干杯 基督教
I have seen a couple of really fancy one-page websites in the past where certain elements would appear when scrolling through a page. From what I remember the effect seemed to be written using css only. I believe that should be possible with the z-index and position property?
Unfortunately, I can't find the pages again.
Anyone having a working example?
Cheers
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说,这是通过
z-index
完成的,但另一个关键是让下面的项目具有position:fixed
,如下所示:然后,当您向下滚动时页面,
#uncover
将被显示,因为无论您滚动到哪里,它都会与浏览器窗口保持相同的关系,但#blocker
会随页面向上滚动。我在这里创建了一个小提琴示例。This is accomplished with
z-index
just like you said, but the other key is having the item beneath to haveposition:fixed
, like so:Then when you scroll down the page,
#uncover
will be revealed as it will stay in the same relation to the browser window no matter where you scroll, but#blocker
scrolls up with the page. I've created a fiddle example here.