2

向上滚动时使用机车滚动会导致一些闪烁。上半部分的元素出现在视口中,延迟很小但很明显(可能为 0.1 秒)。我看了很多演示,但几乎所有这些网站都有相同的问题。例如,官方演示:查看“04.固定元素”部分 - 向上滚动时图像闪烁。

使用 Locomotion 平滑滚动时是否不可避免?

Windows 上的 PS Chrome 97.0

更新 1 由于实施了虚拟滚动条,该问题仅出现在基于 Chrome 的 94 版浏览器上。

找到了一个临时解决方案:

.has-scroll-smooth 
{position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;}

但是,如果您对页面上的某些元素使用固定位置,这会破坏布局。

4

1 回答 1

0

省去麻烦并使用本机方法

测试代码在这里

并制作自己的功能,例如:

// scroll to element smoothly via native built in function on said element
// just change x13 to the id of your element or use the scrollIntoView Function on an element which you can get from various document.querySelector or others.

document.getElementById('x13').scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
于 2022-01-15T10:45:34.107 回答