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"});//缓慢到达那个位置

 

posted @ 2017-12-08 17:30  rachelch  阅读(535)  评论(0)    收藏  举报