加固定导航栏时,滚动scrollbar定位不准确的问题
scrollbar定位
之前试过用scrollIntoView方法去做滚动定位处理,但是一旦出现固定导航栏的情况就会被遮盖一部分,不能做计算。
document.getElementById('').scrollIntoView({ behavior:'smooth' });
如下方法正好可以解决此问题,scrollTo方法也可增加滑动动画效果,以及滚动位置的起始点:top,bottom
//ID是定位的锚点
let top = document.getElementById(ID).offsetT.
原创
2021-02-02 11:09:43 ·
1394 阅读 ·
0 评论