html - 背景附件 : fixed 的替代品

标签 html css background-attachment

由于 background-attachment:fixed 在某些移动浏览器(例如在 iOS 上)上不起作用,有哪些替代方案,特别是在尝试实现以下演示时:http://cppforums.ludost.net/test/test.html

CSS:

.sec1 { 
  min-height: 1000px;
  background: #222 url('wallpaper-2959361.jpg') no-repeat center top fixed;
}

.sec2 { 
  min-height: 1000px;
  background: #222 url('wallpaper-1829278.jpg') no-repeat center top fixed;
}

HTML:

<div class="sec1">text</div>
<h1>Title 1</h1>
<div class="sec2">more text</div>
<h1>Title 2</h1>
<div class="sec1">even more text</div>

关于如何以适用于所有浏览器的方式实现演示的任何建议?最好是仅 CSS 的解决方案。

最佳答案

    .bg 
    {
      background-image: url(bg.jpg);
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
      position: fixed;
      top: 0px;
      bottom: 0px;
      left: 0px;
      right: 0px;
      z-index: -1;
      -webkit-transform: translateZ(0);
      pointer-events: none;
    }

请看这个例子:https://rawgit.com/arnaudbreton/background-fixed-chrome-rendering-issue/master/index-without-rendering-issue.html

取自: http://blog.mention.com/building-a-beautiful-homepage-how-we-nailed-down-chrome-performance-rendering-issues/

关于html - 背景附件 : fixed 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21240465/

相关文章:

css - Firefox 中的固定位置背景图像不适用于转换后的元素。这是一个 FF 错误吗?

css - 背景附件固定和位置固定元素的 Chrome 问题

javascript - 有什么好的方法可以防止人们复制我的源代码?

javascript - 使用 javascript 更改 onclick 值

html - 在不使用边距的情况下删除 <p> 之间的间距?

javascript - 谷歌地图标记 — 设置背景颜色

css - Bootstrap 3.0 中的自定义第一个 child

javascript - 单击滚动更多数据

css - 网站背景

html - 背景附件:修复了在 Firefox 中无法工作的问题