2016-07-22 66 views
1

這是我的代碼:背景附件:固定不工作在Android/IOS

<div style="width: 100vw; height: 100vh; background-image: url(img/kid1/1.jpg); background-attachment: fixed; background-size: cover"></div> 
<div style="width: 100vw; height: 100vh; background-image: url(img/kid1/2.jpg); background-attachment: fixed; background-size: cover"></div> 

它正常工作與我的筆記本電腦Chrome,但不與應用鍍鉻或在Android/IOS任何Web瀏覽器(智能設備) 。事情是我在w3c練習mod上試過這段代碼,它在我的手機上工作,所以我的代碼沒有錯,我的手機沒有錯,所以這裏有什麼問題?我該如何解決這個問題?我是新手,所以這可能是一個noob問題,但這個錯誤真的讓我懊惱......

+0

檢查這一點,也許可以解決您的問題:http://stackoverflow.com/questions/24154666/background-image-size-cover-not-working-on-ios/43058483#43058483 –

回答

0

事業部蓋(1版):

HTML5:

<div class="fixed"></div> 

CSS3:

.fixed { 
background: url(img/kid1/1.jpg) no-repeat center center fixed; 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
} 

OR:

股利蓋(第2版):

HTML5:

<div class="fixed" style="background: url(img/kid1/1.jpg) no-repeat center center fixed;"></div> 

CSS3:

.fixed { 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
} 

上的 「HTML」 標籤(全屏蓋):

html { 
background: url(img/kid1/1.jpg) no-repeat center center fixed; 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
} 

簡單。 :)

+0

但我看不出差異。你有沒有發現我的代碼有問題? –

+0

有時候是「background-attachment:fixed;」在android/ios上的越野車。你應該寫:「」background:url(img/kid1/1.jpg)no-repeat center center fixed;「 – DEHM

+0

當問題解決後投票:) – DEHM

-1

bacground-attachment:fixed;

.fixed { 
    background: url(img/kid1/1.jpg) no-repeat center center; 
    background-attachment:fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
    } 
+0

請拼寫正確。你的答案中的'bacground-attachment'是拼寫錯誤。另外,請不要在同一個問題上發佈兩個非常相似的答案。謝謝。 – Pang

3

background-attachment: fixed在許多手機瀏覽器上不受支持。

如果你在這裏檢查:http://caniuse.com/#feat=background-attachment,你會看到在你的筆記本電腦上,你得到不同的結果,從你的手機。

到目前爲止,我發現最好的辦法是將手機上的圖像作爲沒有視差的圖像。

希望它有助於