html - 在 Chrome 上滚动后,背景图像附件固定(视差)滞后/闪烁

标签 html css google-chrome background-image parallax

我的视差图像存在滞后/闪烁问题,我注意到该问题发生在一些页面滚动之后,并且仅在猫头鹰轮播的页面中发生。我找到了很多解决方案,但它们都不适合我。

我会在不使用 javascript 库的情况下解决它,你能给我一些提示吗?

你能在这个 page 看到我的问题吗,在标题为“1991 年以来的承包商和施工经理”的部分中。

最佳答案

很简单..你可以试试这段代码。

HTML

<div id="title" class="slide header">
  <h1>Pure CSS Parallax</h1>
</div>

<div id="slide1" class="slide">
  <div class="title">
    <h1>Slide 1</h1>
    <p>Lorem ipsum dolor sit amet, in velit iudico mandamus sit, persius dolorum in per, postulant mnesarchum cu nam. Malis movet ornatus id vim, feugait detracto est ea, eam eruditi conceptam in. Ne sit explicari interesset. Labores perpetua cum at. Id viris docendi denique vim.</p>
  </div>
</div>

<div id="slide2" class="slide">
  <div class="title">
    <h1>Slide 2</h1>
    <p>Lorem ipsum dolor sit amet, in velit iudico mandamus sit, persius dolorum in per, postulant mnesarchum cu nam. Malis movet ornatus id vim, feugait detracto est ea, eam eruditi conceptam in. Ne sit explicari interesset. Labores perpetua cum at. Id viris docendi denique vim.</p>
  </div>
  <img src="http://lorempixel.com/output/abstract-q-c-640-480-6.jpg">
  <img src="http://lorempixel.com/output/abstract-q-c-640-480-4.jpg"> 
</div>

<div id="slide3" class="slide">
  <div class="title">
    <h1>Slide 3</h1>
    <p>Lorem ipsum dolor sit amet, in velit iudico mandamus sit, persius dolorum in per, postulant mnesarchum cu nam. Malis movet ornatus id vim, feugait detracto est ea, eam eruditi conceptam in. Ne sit explicari interesset. Labores perpetua cum at. Id viris docendi denique vim.</p>
  </div>
</div>

<div id="slide4" class="slide header">
    <h1>The End</h1>
</div>

CSS

@import url(http://fonts.googleapis.com/css?family=Nunito);

html {
  height: 100%;
  overflow: hidden;
}

body { 
  margin:0;
  padding:0;
    perspective: 1px;
    transform-style: preserve-3d;
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  font-family: Nunito;
}

h1 {
   font-size: 250%
}

p {
  font-size: 140%;
  line-height: 150%;
  color: #333;
}

.slide {
  position: relative;
  padding: 25vh 10%;
  min-height: 100vh;
  width: 100vw;
  box-sizing: border-box;
  box-shadow: 0 -1px 10px rgba(0, 0, 0, .7);
    transform-style: inherit;
}

img {
  position: absolute;
  top: 50%;
  left: 35%;
  width: 320px;
  height: 240px;
  transform: translateZ(.25px) scale(.75) translateX(-94%) translateY(-100%) rotate(2deg);
  padding: 10px;
  border-radius: 5px;
  background: rgba(240,230,220, .7);
  box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}

img:last-of-type {
  transform: translateZ(.4px) scale(.6) translateX(-104%) translateY(-40%) rotate(-5deg);
}

.slide:before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left:0;
  right:0;
}

.title {
  width: 50%;
  padding: 5%;
  border-radius: 5px;
  background: rgba(240,230,220, .7);
  box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}

.slide:nth-child(2n) .title {
  margin-left: 0;
  margin-right: auto;
}

.slide:nth-child(2n+1) .title {
  margin-left: auto;
  margin-right: 0;
}

.slide, .slide:before {
  background: 50% 50% / cover;  
}

.header {
  text-align: center;
  font-size: 175%;
  color: #fff;
  text-shadow: 0 2px 2px #000;
}

#title {
  background-image: url("http://lorempixel.com/output/abstract-q-c-640-480-6.jpg");
   background-attachment: fixed;  
}

#slide1:before {
  background-image: url("http://lorempixel.com/output/abstract-q-c-640-480-4.jpg");
  transform: translateZ(-1px) scale(2);
  z-index:-1;
}

#slide2 {
  background-image: url("http://lorempixel.com/output/abstract-q-c-640-480-3.jpg");
  background-attachment: fixed;
}

#slide3:before {
  background-image: url("http://lorempixel.com/output/abstract-q-c-640-480-5.jpg");
  transform: translateZ(-1px) scale(2);
  z-index:-1;
}

#slide4 {
  background: #222;
}

关于html - 在 Chrome 上滚动后,背景图像附件固定(视差)滞后/闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32399656/

相关文章:

javascript - jquery selectpicker 不适用于动态生成的内容

css - "undefined is not a function"咕噜声少

javascript - 制作一个防止存储在浏览器历史记录中的网页

html - 页面底部的div

java - ÅØÆ - HTML -> Java -> MySQL -> Java -> HTML 的文本编码出现问题

html - 元素不会排队

c# - 以编程方式访问 Google Chrome 主页或起始页

php - Chrome 加载旧版本的 Javascript 文件

html - 在 HTML 链接上放置背景图片

html - 如何在 Bootstrap 中将半径添加到 <thead>