我有2个html元素。当我点击第一个元素时,我想滚动到第二个元素,因为我希望滚动顺利,我不想使用jQuery或任何js来解决这个特殊问题我使用scroll-behavior
css属性:
<style>
body {
scroll-behavior: smooth;
}
</style>
<body>
<a id="firstElement" href="#secondElement">
<!-- some other divs -->
<div id="secondElement"
</body>
当我点击第一个元素时它会让我到第二个,但平滑滚动只发生在Firefox中,据我所知,它也应该发生在Google Chrome中。当我检查body
元素时,我看到一条警告消息,说明
未知的属性名称
for&#34; scroll-behavior&#34;。