如何删除视差内部滚动条

时间:2018-07-21 22:15:05

标签: html css parallax

我正在尝试在我网站的“关于我们”页面上添加视差效果。我设法用纯CSS创建效果,但是container div中有一个内部滚动条。

PS。这是在magento商店上,我无法更改main div

这是我的html

<div class="container">
   <div class="parallax-wrapper">
      <div class="section parallax bg1"><span>Your Passion Is Our Passion!</span></div>
      <div class="section static">
         <p>Since more than 12 years ....</p>
      </div>
      <div class="section parallax bg2"><span>Large Choice Of Products</span></div>
      <div class="section static">
         <p>We are proud to offer you a large variety of products for every budget and taste.</p>
      </div>
      <div class="section parallax bg3"><span>Dedicated Customer Service</span></div>
      <div class="section static">
         <p>Our staff's only goal is to offer you a unique and professional experienxe.</p>
      </div>
      <div class="section parallax bg1"><span>Happy Shopping!</span></div>
   </div>
</div>

和CSS

.parallax-wrapper{
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    perspective: 2px;
}

.section{
    position: relative;
    height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 0 5px #000;
}

.parallax::after{
    content: " ";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transform: translateZ(-1px) scale(1.5);
    background-size: 100%;
    z-index: -1;
}

.static {
  background: red;
  height: 200px;
}

.bg1::after {
  background-image: url(/app/design/frontend/TemplateMonster/md/web/images/bg1.jpg);
}

.bg2::after {
  background-image: url(/app/design/frontend/TemplateMonster/md/web/images/bg2.jpg);
}

.bg3::after {
  background-image: url(/app/design/frontend/TemplateMonster/md/web/images/bg3.jpg);
}

我希望在用户滚动整个页面时,而不是在我用代码意外创建的内部滚动条时,视差效果有效。

1 个答案:

答案 0 :(得分:0)

添加了body CSS

body {
  margin: 0px; /* this one has been added */
}

.parallax-wrapper{
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    perspective: 2px;
}

.section{
    position: relative;
    height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 0 5px #000;
}

.parallax::after{
    content: " ";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transform: translateZ(-1px) scale(1.5);
    background-size: 100%;
    z-index: -1;
}

.static {
  background: red;
  height: 200px;
}

.bg1::after {
  background-image: url(https://loremflickr.com/320/240);
}
<div class="container">
   <div class="parallax-wrapper">
      <div class="section parallax bg1"><span>Your Passion Is Our Passion!</span></div>
      <div class="section static">
         <p>Since more than 12 years ....</p>
      </div>
      <div class="section parallax bg2"><span>Large Choice Of Products</span></div>
      <div class="section static">
         <p>We are proud to offer you a large variety of products for every budget and taste.</p>
      </div>
      <div class="section parallax bg3"><span>Dedicated Customer Service</span></div>
      <div class="section static">
         <p>Our staff's only goal is to offer you a unique and professional experienxe.</p>
      </div>
      <div class="section parallax bg1"><span>Happy Shopping!</span></div>
   </div>
</div>

相关问题