由于 background-attachment:fixed 在某些移动浏览器(例如在 iOS 上)上不起作用,有哪些替代方案,特别是在尝试实现以下演示时:http://cppforums.ludost.net/test/test.html
CSS:
.sec1 {
min-height: 1000px;
background: #222 url('wallpaper-2959361.jpg') no-repeat center top fixed;
}
.sec2 {
min-height: 1000px;
background: #222 url('wallpaper-1829278.jpg') no-repeat center top fixed;
}
HTML:
<div class="sec1">text</div>
<h1>Title 1</h1>
<div class="sec2">more text</div>
<h1>Title 2</h1>
<div class="sec1">even more text</div>
关于如何以适用于所有浏览器的方式实现演示的任何建议?最好是仅 CSS 的解决方案。
最佳答案
.bg
{
background-image: url(bg.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: fixed;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
z-index: -1;
-webkit-transform: translateZ(0);
pointer-events: none;
}
关于html - 背景附件 : fixed 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21240465/