1. 使用Element.scrollIntoView()方法
element.scrollIntoView(); // 等同于 element.scrollIntoView(true)
element.scrollIntoView(boolean); // Boolean 型参数。 true: 元素的顶端将和其所在滚动区的可视区域的顶端对齐; false: 元素的底端将和其所在滚动区的可视区域的底端对齐
element.scrollIntoView(options); // Object 型参数
let dom = document.querySelector("#id") // 获取到元素
dom.scrollIntoView({
behavior: "smooth", // 定义动画过渡效果, "auto"或 "smooth" 。默认为 "auto"。
block: "center", // 定义垂直方向的对齐, "start", "center", "end", 或 "nearest"。默认为 "start"。
inline: "center", // 定义水平方向的对齐, "start", "center", "end", 或 "nearest"。默认为 "nearest"
})