美文网首页
getBoundingClientRect()方法实现吸顶效果

getBoundingClientRect()方法实现吸顶效果

作者: Nosaj | 来源:发表于2021-02-18 11:49 被阅读0次

理解:getBoundingClientRect用于获取某个元素相对于视窗的位置集合。集合中有top, right, bottom, left等属性。

  getBoundingClientRect().top:元素上边到视窗上边的距离;

  getBoundingClientRect().right:元素右边到视窗左边的距离;

  getBoundingClientRect().bottom:元素下边到视窗上边的距离;

  getBoundingClientRect().left:元素左边到视窗左边的距离;
image.png

可以根据top属性更改元素css的position属性为sticky 实现吸顶效果

相关文章

网友评论

      本文标题:getBoundingClientRect()方法实现吸顶效果

      本文链接:https://www.haomeiwen.com/subject/acbgxltx.html