我觉得这里有一个显而易见的答案,但我不明白为什么在下面的模拟示例中,#one
没有被#three
“推”上去?
查看 MDN 给出的最后一个示例,似乎粘性元素会相互推开窗口,而这里的#one
和#three
似乎只是彼此滑动。我感觉这可能与高度有关,但任何有关解释的帮助都将不胜感激!
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
color: #000;
font: bold 20vw Helvetica, Arial, sans-serif;
}
.sticky {
position: sticky;
top: 0px;
}
#start {
width: 100%;
height: 50vh;
background: #fff;
}
#one {
height: 100vh;
width: 100%;
background: url('https://picsum.photos/900/1200/?random');
background-position: center;
background-size: cover;
}
#two {
width: 50%;
position: relative;
height: 100vh;
background: url('https://picsum.photos/800/1200/?random');
background-position: center;
background-size: cover;
}
#three {
width: 100%;
height: 100vh;
background: url('https://picsum.photos/700/1200/?random');
background-position: center;
background-size: cover;
}
<div id="start">
<h1>start</h1>
</div>
<div id="one" class="sticky img">
<h1>one</h1>
</div>
<div id="two" class="img">
<h1>two</h1>
</div>
<div id="three" class="sticky img">
<h1>three</h1>
</div>
#two
重叠了#one
(宽度为50%),我希望仍然可以实现这一点? - Jack Clarke#one
div本身固定在顶部,而#two
在其上方通过,之后#three
将#one
推出视野? - Jack Clarke