window.scrollTo() 滚动到文档中的某个坐标
第一种写法:
// 直接指定滚动到x轴和y轴位置
scrollTo(0, 0)
第二种写法:
/** scrollTo(options)
options 有三个参数
- top: 等同于 (y坐标)
- left: 等同于 (x坐标)
- behavior: 类型为string, 表示滚动行为, 支持参数 smooth(平滑滚动), instant(瞬间滚动), 默认值auto, 实测效果等同于instant
*/
// 示例:
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
})