document.querySelector('#需要定位的ID').scrollIntoView({
  behavior: "smooth", // 定义动画过渡效果, "auto"或 "smooth" 之一。默认为 "auto"
  block: "center", // 定义垂直方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 "start"
  inline: "nearest" // 定义水平方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 "nearest"
})

posted on 2022-04-07 17:05  热心市民宗某§  阅读(40)  评论(0)    收藏  举报