简体   繁体   English

纯 CSS 视差背景停止在所有设备/浏览器上工作

[英]CSS-only Parallax background stopped working on all devices/browsers

I noticed this happening a couple of weeks ago on a website that I built and have worked on since 2017. On the landing page of this site , there's two sections that are supposed to have a sort of slow parallax scrolling effect that I implemented with straight CSS (no JavaScript.) For some reason, the parallax effect no longer works on any device that I've tried, with several browsers across multiple devices.几周前,我在我自 2017 年建立并开始工作的网站上注意到了这种情况。在该网站的登录页面上,有两个部分应该具有我用 straight 实现的一种缓慢的视差滚动效果CSS(没有 JavaScript。)出于某种原因,视差效果不再适用于我尝试过的任何设备,跨多个设备的多个浏览器。 The CSS hasn't been updated since probably 2019. It seemed to be working a few weeks ago when I had last checked to update the site. CSS 可能自 2019 年以来就没有更新过。几周前我上次检查更新站点时它似乎还在工作。

here's the relevant CSS if you don't want to open dev tools.如果您不想打开开发工具,请输入相关的 CSS。 I realize some of this is really shoddy, I've done better as a dev since:我意识到其中一些真的很低劣,我作为开发人员做得更好,因为:

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

body{
    background-color: #322e32;
    /*margin: 15px 0 15px 0;*/
    padding-top: 65px;
    min-height: 100%;
    color: #ffffff;
    font-family: 'Raleway', sans-serif;
    -webkit-perspective: 1px;
            perspective: 1px;
    -webkit-transform-style: preserve-3d;
            transform-style: preserve-3d;
    height: 100%;
    overflow-y: scroll;
    overflow-x: hidden;
    position: relative;
}

main{
  min-height: 100vh;
  overflow: hidden;
  display: block;
  position: relative;
  padding-bottom: 30px; /* footer height */
  perspective: 2px;
}

.no-para {
  z-index: 2;
  background: #322e32;
}

.index-tour{
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 1.5vw 48vw 1vw 48vw 1.5vw;
  grid-template-columns: 1.5vw 48vw 1vw 48vw 1.5vw;;
  -ms-grid-rows: 100px 100vh 100px 100vh 75px 100vh 45vh;;
  grid-template-rows: 100px 100vh 100px 100vh 75px 100vh 45vh;
}

#tour-header{
  -ms-grid-column: 1;
      grid-column-start: 1;
  -ms-grid-column-span: 5;
  grid-column-end: 6;
  -ms-grid-row: 1;
      grid-row-start: 1;
  -ms-grid-row-span: 1;
  grid-row-end: 2;
  z-index: 2;
  background: #322e32;
  text-align: center;
}

#tour-gallery{
  -ms-grid-column: 1;
      grid-column-start: 1;
  -ms-grid-column-span: 5;
  grid-column-end: 6;
  -ms-grid-row: 2;
      grid-row-start: 2;
  -ms-grid-row-span: 1;
  grid-row-end: 3;
}

#tour-gallery:before{
  background: url('indexTour1.png');
  -webkit-transform: translateZ(-1px) scale(2);
          transform: translateZ(-1px) scale(2);
}

#tour-gallery-text{
  position: absolute;
  left: 50%;
  margin-right: -25%;
  -webkit-transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  top: 37%;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  padding: 0 5em;
  font-size: 1.3em;
  background: #00000061;
  border-radius: 80px;
}

#tour-portraits{
  -ms-grid-column: 1;
      grid-column-start: 1;
  -ms-grid-column-span: 5;
  grid-column-end: 6;
  -ms-grid-row: 3;
      grid-row-start: 3;
  -ms-grid-row-span: 1;
  grid-row-end: 4;
  /*height: 100px;
  width: 100%;*/
  background: #322e32;
  z-index: 2;
}

#tour-portraits p {
  text-align: center;
}

#tour-pet-portraits{
  -ms-grid-column: 2;
      grid-column-start: 2;
  -ms-grid-column-span: 1;
  grid-column-end: 3;
  -ms-grid-row: 4;
      grid-row-start: 4;
  -ms-grid-row-span: 1;
  grid-row-end: 5;
  background: url('../gallery/01032019A.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 3;
}

#tour-human-portraits{
  -ms-grid-column: 4;
      grid-column-start: 4;
  -ms-grid-column-span: 1;
  grid-column-end: 5;
  -ms-grid-row: 4;
      grid-row-start: 4;
  -ms-grid-row-span: 1;
  grid-row-end: 5;
  background: url('../gallery/79183.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 3;
}

#tour-portraits-text{
  position: absolute;
  /* margin: 54vh 4vw;
  padding-right: 7px;
  padding-left: 7px;
  font-size: 1.3em; */
  background: #0000007d;
  border-radius: 42px;
  text-align: center;
}

#tour-special{
  -ms-grid-column: 1;
      grid-column-start: 1;
  -ms-grid-column-span: 5;
  grid-column-end: 6;
  -ms-grid-row: 6;
      grid-row-start: 6;
  -ms-grid-row-span: 1;
  grid-row-end: 7;
}

#tour-special:before{
  background: url('indexTour2.png');
  -webkit-transform: translateZ(-1px) scale(2);
          transform: translateZ(-1px) scale(2);
}

And the relevant HTML (via PHP, but I doubt that matters):以及相关的 HTML(通过 PHP,但我怀疑这是否重要):

  <div id='tour-header'>
    <h1>A Tour Of The Studio...</h1>
  </div>
  <div id='tour-gallery' class="parallax-back">
    <div id='tour-gallery-text'>
      <h2><b>Main Gallery</b></h2>
      <p>The Main Gallery includes original works of art by Anni that are available for purchase at reasonable prices.
        We normally ship pieces via USPS, but if you're local to the Greater Atlanta Area, we can arrange for pick up.
        <b>Please note that we are unable to ship outside of the United States at this time!</b></p><br />
      <p style='text-align: center;'><a href='gallery.php' class="purchaseButton" role="button">Visit Main Gallery →</a></p>
    </div>
  </div>
  <div id='tour-portraits'>
    <h2><b>Custom Portraits</b></h2>
    <p>Commissions For Portraits Are <span style="color: #9bffb5;"><b>Currently Open!</b></span></p>
  </div>
  <div id='portraits-gap2' class='no-para'></div>
  <div id='tour-pet-portraits'>
    <div id='tour-portraits-text' class='tour-portraits-text-margins1'>
      <h3><b>Pet Portraits</b></h3>
      <p>Commission Anni to perfectly capture your furbaby (or fur children) on canvas!</p><br />
      <p style='text-align: center;'><a href='petportrait.php' class="purchaseButton" role="button">Learn More →</a></p>
    </div>
  </div>
  <div id='portraits-gap1' class='no-para'></div>
  <div id='tour-human-portraits' class='no-para'>
    <div id='tour-portraits-text' class='tour-portraits-text-margins2'>
      <h3><b>People Portraits</b></h3>
      <p>Want to see yourself or a loved one painted? Let Anni do it in immaculate detail!</p><br />
      <p style='text-align: center;'><a href='portraits.php' class="purchaseButton" role="button">Learn More →</a></p>
    </div>
  </div>
  <div id='portraits-gap3' class='no-para'></div>
  <div id='portraits-bottom' class='no-para'></div>
  <div id='tour-special' class='parallax-back'>
    <div id='tour-gallery-text'>
      <h2><b>Special Gallery</b></h2>
      <p>Here you can take a look at some of Anni's past commissions, sold/donated original pieces, and select works that are permanently kept in the studio.</p><br />
      <p style='text-align: center;'><a href='special.php' class="purchaseButton" role="button">Visit Special Gallery →</a></p>
    </div>
  </div>

Thing is, when I look up other methods of implementing parallax with just CSS, a lot of those CodePens and demos, some as recent as this year, don't work as intended either.问题是,当我查找仅使用 CSS 实现视差的其他方法时,许多 CodePens 和演示(有些是今年最近的)也无法按预期工作。 Did something happen with the rules of CSS or something? CSS 的规则发生了什么事吗? Because this used to work, I swear!因为这曾经有效,我发誓! Any help is appreciated!任何帮助表示赞赏!

Mine broke too, I am not sure what changed, but if you add我的也坏了,我不确定发生了什么变化,但如果你添加

transform-style: preserve-3d;

to your paralax container it should fix it.到您的视差容器,它应该修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM