关于js实现点击按钮平滑回到顶部的方法
HTML部分
<body>
<div onclick="returnTop()">回到顶部</div>
</body>
javascript部分
function returnTop(){
document.documentElement.scrollIntoView({
behavior:'smooth'
})
}
该文章介绍了如何使用JavaScript实现点击页面上的一个元素(如‘回到顶部’按钮),使页面平滑滚动回到顶部的效果。关键函数是`scrollIntoView`,并设置`behavior`属性为smooth,以实现平滑滚动动画。
<body>
<div onclick="returnTop()">回到顶部</div>
</body>
function returnTop(){
document.documentElement.scrollIntoView({
behavior:'smooth'
})
}
609
548
2140

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