自动水平滚动div

问题描述 投票:0回答:1

我有一个带有三个锚标记的可滚动 div。 Here you can see the div with the three a tags. 在代码中,我使用 Intersection Observer,当我到达页面上的标题时,它会突出显示该锚标记。现在,当我到达页面上的标题时,我想滚动到特定的锚标记。我要怎么做呢? 我尝试使用滚动方法和属性,但它没有达到我想要的效果。

javascript html css methods scroll
1个回答
0
投票

您可以在 Intersection Observer 函数中使用scrollIntoView 属性,如下所示:

document.getElementById("id of the div").scrollIntoView({scroll:"smooth"})
© www.soinside.com 2019 - 2024. All rights reserved.