element元素自带scrollIntoView方法
scrollIntoView 方法用于滚动指定元素的父容器或者当前窗口,使指定的元素对用户可见。
可以满足业务场景,需要滚动到指定区域的需求。
element.scrollIntoView(options):其中 options 参数可选,默认值为{block: "start", inline: "nearest"};还有另外两种情况
如果options是布尔值:true表示滚动到元素的顶部,相当于{block: "start", inline: "nearest"},false表示滚动到元素的底部,即为{block: "end", inline: "nearest"}。
如果options是对象,则其包含下列属性:
block: 定义垂直方向的对齐方式,可选值为start、center、end或者nearest,默认值为start
inline: 定义水平方向的对齐方式,可选值为start、center、end或者nearest,默认值为nearest
behavior: 定义滚动行为,可选值为auto或者smooth、instant,默认值为auto

浙公网安备 33010602011771号