我希望重新创建类似于科普应用的效果。基本上有一个大的背景图片,然后在上面有 HTML/CSS 层。当用户滚动内容时,图像的背景位置应保持不变,而不是滚动。
显然在“常规”浏览器中我会使用 background-attachment:fixed,但这在 ipad 上似乎不起作用。我知道根据 safari 规范 position:fixed 不能像您预期的那样工作 - 但有什么方法可以实现这一点吗?
最佳答案
您可以使用此代码制作固定背景图层来解决此问题。
#background_wrap {
z-index: -1;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-size: 100%;
background-image: url('xx.jpg');
background-attachment: fixed;
}
然后放<div id="background_wrap"></div>
进入<body></body>
<body>
<div id="background_wrap"></div>
</body>
关于css - 使用后台附件 :fixed in safari on the ipad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011226/