ScrollIntoView使用方法:
document.querySelector('id').scrollIntoView({
behavior: "smooth", block: "nearest", inline: "nearest"
});
导致页面上移解决方法:
将最外层div设置为固定定位
div{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
本文介绍了JavaScript中`scrollIntoView`方法的使用,用于元素滚动到视口可见区域。同时,针对该方法可能导致页面上移的问题,提出了解决方案:通过设置最外层div为固定定位来防止页面移动。
ScrollIntoView使用方法:
document.querySelector('id').scrollIntoView({
behavior: "smooth", block: "nearest", inline: "nearest"
});
导致页面上移解决方法:
将最外层div设置为固定定位
div{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
3472
2051
387
373

被折叠的 条评论
为什么被折叠?
