【问题标题】:background attachment: fixed not working on android/ios背景附件:修复无法在 android/ios 上运行
【发布时间】:2016-11-25 19:42:44
【问题描述】:

这是我的代码:

<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,但不适用于应用程序 chrome 或 android/ios(智能设备)上的任何网络浏览器。问题是我确实在 w3c practice mod 上尝试了这个代码,它确实在我的手机上工作,所以我的代码没有错,我的手机没有错,那么这里有什么问题?我该如何解决这个问题?我是新手,所以这可能是一个菜鸟问题,但这个错误真的让我很生气......

【问题讨论】:

标签: html css


【解决方案1】:

很多手机浏览器不支持background-attachment: fixed

如果您在此处查看:http://caniuse.com/#feat=background-attachment,您会看到在笔记本电脑上获得与手机上不同结果的原因。

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

希望对你有帮助

【讨论】:

    【解决方案2】:

    Div 封面(第 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;
    }
    

    或者:

    Div 封面(第 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;
    }
    

    简单。 :)

    【讨论】:

    • 但是我看不出区别。你发现我的代码有什么问题吗?
    • 有时是“背景附件:固定;” android/ios 上的越野车。你应该写:""背景:url(img/kid1/1.jpg) no-repeat center center fixed;"
    • With: "背景:url(img/kid1/1.jpg) no-repeat center center fixed";在 html 和“-webkit-background-size:封面;-moz-background-size:封面;-o-background-size:封面;背景尺寸:封面;”在 css 或背景尺寸中:cover !important; ?
    • 是的......这就是我生气的原因......你可以查看这个 khanhlam-nguyen.com
    • css-tricks.com/perfect-full-page-background-image 这是一个很酷的演示示例。也许这对你有用......
    【解决方案3】:

    在移动使用视角上适当地视差。使用 JS 或背景附件的视差:已修复;在手机上无法正常工作。

    https://developers.google.com/web/updates/2016/12/performant-parallaxing

    【讨论】:

      【解决方案4】:

      免费附件:固定;

       .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;
          }
      

      【讨论】:

      • 请正确拼写。 bacground-attachment 在您的答案中拼写错误。另外,请不要在同一个问题上发布两个非常相似的答案。谢谢。
      猜你喜欢
      • 2013-07-13
      • 2014-11-16
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多