html
<div style={{background:"red",height:"200vh"}}>
<div style={{ width: "100px", height: "100px", background: "#000" }}></div>
<div style={{width:"100px",height:"100px",background:"green",position:"sticky",top:"0px"}}></div>
</div>
css
position: sticky;
top: 20px;
sticky 定位失效原因:
1.必须 top/left/right/bottom 值设置一个
2.body。html 等高度不能为100vh屏幕高度
3.sticky定位的层的父级或者上级div的overflow不能为hidden;