// 页面滚动到顶部
// 方法一
document.body.scrollTop=document.documentElement.scrollTop=0
// 方法二
document.body.scrollIntoView()
// scrollIntoView 是元素也有的方法, 可以用在页面元素上,例如
document.getElementById('id').scrollIntoView()
js滚动到页面顶部
最新推荐文章于 2024-10-31 16:02:32 发布
本文介绍了两种将网页滚动到顶部的方法:一是通过设置 document.body.scrollTop 和 document.documentElement.scrollTop 的值为0;二是使用 document.body.scrollIntoView() 方法。此外还提到了 scrollIntoView 方法可以应用于特定元素,如通过 document.getElementById('id').scrollIntoView() 实现。
5415

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



