2. 在CSS文件中,设置`scroll-behavior`属性为`smooth`。
[mw_shl_code=css,true]
html {
scroll-behavior: smooth;
}
[/mw_shl_code]
3. 在JavaScript文件中,使用`scrollIntoView()`方法将目标元素滚动到可视区域。
[mw_shl_code=javascript,true]
var element = document.getElementById("section1");
element.scrollIntoView();
[/mw_shl_code]