我在想为什么position: sticky
在某些x轴滚动时有效,但一旦你滚过屏幕宽度的初始宽度,你的“粘性div”就停止了粘合。
在这个例子中,我有一个左侧边栏,它会粘在左边(请注意,在我的实际项目中,左侧div和右侧div都需要沿着y轴上下滚动,因此我们只想要左侧边栏固定)。
是否有其他CSS参数我可以定义,比如
left-sticky-distance=999999%
或者类似这样的东西?
下面是一些演示测试代码
<html>
<body>
<div style='
position:sticky;
z-index:1;
left:0;
width:100px;
height:200px;
overflow: hidden;
background-color:#ff0000;
opacity:0.8;'
>
</div>
<div style='position: absolute; top: 10; left: 10; width: 200; height:50px; background-color: blue'>B</div>
<div style='position: absolute; top: 10; left: 110; width: 200; height:50px; background-color: blue'>C</div>
<div style='position: absolute; top: 10; left: 210; width: 200; height:50px; background-color: blue'>D</div>
</body>
<html>