固定位置与透视

时间:2017-01-08 23:20:49

标签: html css parallax

这是我的 JS FIDDLE

我希望我的div id="text"得到解决。但它不适用于我的代码......问题是我需要将所有内容保存在div id="wrapper"中。我能怎么做?如果您有其他解决方案对我的图像有视差效果(仅限css),请告诉我。

body {
  overflow-x: hidden;
  margin:0;
}

#text {
  font-size: 70px;
  height: 100%;
  width: 100%;
  position: fixed;
}
#intro {
  font-size: 30px;
  width: 100%;
  border:3px solid yellow;
  position: absolute;
}

#wrapper {

  transform-style: preserve-3d;
  height: 100%;
  perspective: 1px;
  overflow-x: hidden;
  border:3px solid cyan;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;

}

#wrapper section {

    position: relative;
    height: 200px;
    width: 300px;
    background:pink;
    box-sizing: border-box;
    border:3px solid red;
    transform-style: inherit;
    overflow: hidden; 
    margin: 100px;

  }

#wrapper section .back {
      width: 300px;

      border:3px solid green;
      transition: transform 1s ease-out;
      height:200px;
      background-position: center center;
      transform: translateZ(-0.6px) scale(1.5); }

.back {
    background-image: url(http://wallpaper-gallery.net/images/background-image/background-image-18.jpg); }





#wrapper section .back:hover {

  opacity: 0.5;
  transform:translateZ(-0.4px) scale(2.6); }

1 个答案:

答案 0 :(得分:2)

这是:

body {
  overflow-x: hidden;
/*    position:static;*/
    margin:0;

}

#text {
  font-size: 70px;
  height: 100%;
  width: 100%;
  position: fixed;
  pointer-events: none;
}
#intro {
  font-size: 30px;
  width: 100%;
  border:3px solid yellow;
  position: absolute;
}

#wrapper {

  transform-style: preserve-3d;
  height: 100%;
  perspective: 1px;
  overflow-x: hidden;
  border:3px solid cyan;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;

}

#wrapper section {

    position: relative;
    height: 200px;
    width: 300px;
    background:pink;
    box-sizing: border-box;
    border:3px solid red;
    transform-style: inherit;
    overflow: hidden; 
    margin: 100px;

  }

#wrapper section .back {
      width: 300px;

      border:3px solid green;
      transition: transform 1s ease-out;
      height:200px;
      background-position: center center;
      transform: translateZ(-0.6px) scale(1.5); }

.back {
    background-image: url("http://wallpaper-gallery.net/images/background-image/background-image-18.jpg"); }





#wrapper section .back:hover {

  opacity: 0.5;
  transform:translateZ(-0.4px) scale(2.6); }
<div id="wrapper">
  <div id="intro">
    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
  </div>
  <section id="frame1"><div class="back"></div></section>
  <section id="frame3"><div class="back"></div></section>
  <section id="frame5"><div class="back"></div></section>
  <section id="frame7"><div class="back"></div></section>
</div>
<div id="text">
  <h1>Hello</h1>
</div>

您需要将真正的 fixed元素放在DOM中(作为#wrapper的兄弟),并将其pointer-events:none赋予它,以便{{1} (包括 滚动 )传递给需要的其他pointer-events定位元素(fixed,其中包含其余内容)滚动以使你的视差效果发生。