爲了使圖像靜止並在這些圖像上滾動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