2016-07-22 67 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,你会看到在你的笔记本电脑上,你得到不同的结果,从你的手机。

到目前为止,我发现最好的办法是将手机上的图像作为没有视差的图像。

希望它有助于