html - 即使到达页面末尾,覆盖元素 div 仍在滚动

标签 html css

*{
  margin: 0;
  padding: 0;
}

body{
  font-family: helvetica , sans-serif;
  background-color: #1E1E20;
}

.parallax-container {
  /* The image used */
  background-image: url("/image/BlF.jpg");
  animation-name: pixels;
  animation-duration: 800ms;
  animation-timing-function: steps(8,end);
  animation-delay: initial;
  animation-iteration-count: infinite;
  animation-play-state: initial;
  position: relative;
  /* Set a specific height */
  min-height: 800px; 
  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

@keyframes pixels {
  100% {
    background-position: 100% 0;
  }
}

.parallax img{
  z-index: 2;
  position: fixed;
  top: 0px;
  padding: auto;
}

.header_nav_container a, h3, h4{
  font-family: Helvetica,sans-serif;
  font-size: 40px;
  font-weight: bold;
  color:white;
}

.header_nav_container h1{
  font-family: Helvetica, sans-serif;
  font-size: 80px;
  text-align: center;
  color: white;
  top: 250px;
  z-index: 4;
  position: relative;
}

.header_nav_container a{
  top: 50px;
  left: 50px;
  text-decoration: none;
  position: relative;
}

.header_nav_container h3{
  top: 50px;
  right: 50px;
  position: absolute;
}

.header_nav_container h4{
  top:90px;
  right: 50px;
  position: absolute;
  font-size: 30px;
  color: yellow;
}


.header_nav_container span{
  text-shadow: 8px 8px black;
}

.projects_container h1{
  font-size: 50px;
  text-align: center;
  color: white;
  font-family: helvetica, sans-serif;
  margin-top: 20px;
}

.front p{
  padding: 10px;
  text-align: center;
  font-family: helvetica, sans-serif;
  font-size: 30px;
  color:white;
}

.underscore{
  color: yellow;
}


.flip3D{ width:240px; height:200px; margin:150px 60px; float:left; }
.flip3D > .front{
  position:absolute;
  transform: perspective( 600px ) rotateY( 0deg );
  background:#1E1E20; width:300px; height:300px; border-radius: 10px;
  backface-visibility: hidden;
  transition: transform .5s linear 0s;
}
.flip3D > .back{
  position:absolute;
  transform: perspective( 600px ) rotateY( 180deg );
  background: #80BFFF; width:300px; height:300px; border-radius: 10px;
  backface-visibility: hidden;
  transition: transform .5s linear 0s;
}
.flip3D:hover > .front{
  transform: perspective( 600px ) rotateY( -180deg );
}
.flip3D:hover > .back{
  transform: perspective( 600px ) rotateY( 0deg );
}

.pic1{
  border-radius: 7px;
}

.front{
  border: 2px solid yellow;
}

.projects{
  background-attachment: scroll;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}

覆盖 PROJECTS div 存在问题。它甚至在结束后向下滚动,使后面的背景可见。

This is the picture in the background. (grey.jpg)

This is the picture on the top of the background. (shadow.png)

我希望滚动效果这样结束。

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_parallax

最佳答案

*{
  margin: 0;
  padding: 0;
}

body{
  font-family: helvetica , sans-serif;
  background-color: #1E1E20;
}

.parallax-container {
  /* The image used */
  background-image: url("/image/BlFbi.jpg");
  animation-name: pixels;
  animation-duration: 800ms;
  animation-timing-function: steps(8,end);
  animation-delay: initial;
  animation-iteration-count: infinite;
  animation-play-state: initial;
  position: relative;
  /* Set a specific height */
  min-height: 800px; 
  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

@keyframes pixels {
  100% {
    background-position: 100% 0;
  }
}

.parallax img{
  z-index: 2;
  position: fixed;
  top: 0px;
  left: 0;
  right: 0;
  margin: 0 auto;
}

.header_nav_container a, h3, h4{
  font-family: Helvetica,sans-serif;
  font-size: 40px;
  font-weight: bold;
  color:white;
}

.header_nav_container h1{
  font-family: Helvetica, sans-serif;
  font-size: 80px;
  text-align: center;
  color: white;
  top: 250px;
  z-index: 4;
  position: relative;
}

.header_nav_container a{
  top: 50px;
  left: 50px;
  text-decoration: none;
  position: relative;
}

.header_nav_container h3{
  top: 50px;
  right: 50px;
  position: absolute;
}

.header_nav_container h4{
  top:90px;
  right: 50px;
  position: absolute;
  font-size: 30px;
  color: yellow;
}


.header_nav_container span{
  text-shadow: 8px 8px black;
}

.projects h1{
  position: relative;
  z-index: 5;
  font-size: 50px;
  text-align: center;
  color: white;
  font-family: helvetica, sans-serif;
  margin-top: 20px;
}

.front p{
  padding: 10px;
  text-align: center;
  font-family: helvetica, sans-serif;
  font-size: 30px;
  color:white;
}

.underscore{
  color: yellow;
}


.flip3D{ width:240px; height:200px; margin:150px 60px; float:left; }
.flip3D > .front{
  position:relative;
  transform: perspective( 600px ) rotateY( 0deg );
  background:#1E1E20; width:300px; height:300px; border-radius: 10px;
  backface-visibility: hidden;
  transition: transform .5s linear 0s;
}
.flip3D > .back{
  position:absolute;
  transform: perspective( 600px ) rotateY( 180deg );
  background: #80BFFF; width:300px; height:300px; border-radius: 10px;
  backface-visibility: hidden;
  transition: transform .5s linear 0s;
}
.flip3D:hover > .front{
  transform: perspective( 600px ) rotateY( -180deg );
}
.flip3D:hover > .back{
  transform: perspective( 600px ) rotateY( 0deg );
}

.pic1{
  border-radius: 7px;
}

.front{
  border: 2px solid yellow;
}

.projects{
  background-attachment: scroll;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}
.projects_container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    height: 100%;
    background-color:#1E1E20;
    position: relative; 
    top: 0px; 
    z-index: 3;
    margin-top: -80px;
}
<header>
  <div class="parallax-container">
    <nav class="header_nav_container">
      <h3>HAHAHA</h3>
      <br>
      <h4>Portfolio</h4>
      <a href="www.google.com/about">About</a>
      <h1>Hi,I'm <span>HAHA</span> </h1>
    </nav>
    <div class="parallax"><img src="/image/8pYB9.png" width="500px" 
      height="800px"></div>
  </div>
</header>
<section class="projects">
  <h1>PROJECTS<span class="underscore">_</span></h1>
  <div class="projects_container">
    <div class="flip3D">
      <div class="back">Box 1 - Back</div>
      <div class="front"></div>
    </div>
    <div class="flip3D">
      <div class="back">Box 2 - Back</div>
      <div class="front">Box 2 - Front</div>
    </div>
    <div class="flip3D">
      <div class="back">Box 3 - Back</div>
      <div class="front">Box 3 - Front</div>
    </div>
    <div class="flip3D">
      <div class="back">Box 4 - Back</div>
      <div class="front">Box 4 - Front</div>
    </div>
  </div>
</section>

https://jsfiddle.net/Sampath_Madhuranga/xpvt214o/616850/

试试这个。它工作正常。如果有任何问题,请告诉我。 谢谢。

关于html - 即使到达页面末尾,覆盖元素 div 仍在滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857965/

相关文章:

html - CSS动画图片的两半在中间相遇(响应)

html - 为什么这个div这么大?

html - 如何在 Magento Go 中添加条件 CSS 类?

Jquery 选择 href 到 JPG

javascript - 使用express在前端读取Base64图像

html - 使用 CSS 设置外部图像样式

html - 顶部和底部固定高度与流体高度中间

javascript - Canvas 图像绘制不起作用

javascript - 如何在表格的 td 鼠标悬停时更改颜色?

javascript - Babylon.js 网格拾取和忽略一些网格