scrollIntoView方法滚动到指定元素,进入浏览器的可见区域

document.getElementById("test").scrollIntoView()

使用css中scroll-margin设置滚动到该元素的距离

#test{
	scroll-margin: 40px;
}

更多推荐