为了使图像静止并在这些图像上滚动div的其余部分,我在网页中使用了背景图像,绝对位置和-1 z-index。它在Web浏览器中的工作完美无瑕,但我无法在手机中获得相同的功能。网页浏览器中的移动视图显示了它应该工作的方式,但其余的div不会在移动浏览器中滚动浏览这些图像,而与web浏览器不同,图像也会滚动。移动浏览器中的绝对图像不会保持绝对
下面是JsFiddle link下面的代码。
HTML
<div class="container">
<div class="section1">lorem ipsum dolar imit</div>
<div class="section3">
<div class="section3-img"></div>
</div>
<div class="section1">lorem ipsum dolar imit</div>
</div>
CSS
body{margin:0; padding:0;}
.container{height:800px; position:relative;}
.section1{
width:100%;
height:400px;
background-color:purple;
color:white;
z-index:10;
}
.section2, .section3{
width:100%;
height:300px;
overflow:hidden;
position:relative;
}
.section3-img{
background-size: cover;
z-index:-100;
width:100%;
height:300px;
position:absolute;
background:url('http://i.istockimg.com/file_thumbview_approve/81531733/6/stock-photo-81531733-texture-of-the-oak-stump-background.jpg') 0 top repeat fixed;
}
PS:我在android手机chrome浏览器还没有测试。
Safari移动不喜欢背景位置。请参阅http://stackoverflow.com/questions/23236158/how-to-replicate-background-attachment-fixed-on-ios – jbrya029