Element.scrollIntoView()
Element.scrollIntoView()
这是JS的一个原生api,调用后,浏览器会滚动至目标元素的位置
api文章:https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView
//滚动到box所在的位置
var element = document.getElementById("box");
element.scrollIntoView(); //迅速到达那个位置
element.scrollIntoView({behavior: "smooth"});//缓慢到达那个位置

浙公网安备 33010602011771号