Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

前端如何实现滚动到某个位置,div固定,下方覆盖该div?

类似华为这个网站的效果:

https://consumer.huawei.com/cn/phones/mate-x-s/

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

sticky 定位,z-index 较低就完事了。

Sticky Practice - CodePen

.front {
  width: 100%;
  height: 80vh;
}

.sticky {
  position: sticky;
  z-index: -1;
  top: 0;
  width: 100%;
  height: 80vh;
  background: orange;
  /* 画个 border 表现出它 sticky */
  border: 32px solid #666;
  box-sizing: border-box;
}

.back {
  width: 100%;
  height: 200vh;
  background: #000;
}
<div class="front"></div>
<div class="sticky"></div>
<div class="back"></div>

参阅:sticky - position - CSS | MDN


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...