,元素的顶端将和其所在滚动区的可视区域的顶端对齐。
相应的
scrollIntoViewOptions: {block: "start", inline: "nearest"}。这是这个参数的默认值。如果为
false,元素的底端将和其所在滚动区的可视区域的底端对齐。相应的
scrollIntoViewOptions: { block: "end", inline: "nearest" }。
Options 对象
{
behavior: "auto" | "instant" | "smooth", 默认为 "auto"。
block: "start" | "end", 默认为 "start"。
inline: "start"| "center"| "end", | "nearest"。默认为 "nearest"。
}
behavior表示滚动方式。
auto表示使用当前元素的
scroll-behavior样式。
instant和
smooth表示
直接滚到底和
使用平滑滚动。
block表示块级元素排列方向要滚动到的位置。对于默认的
writing-mode: horizontal-tb来说,就是竖直方向。
start表示将视口的顶部和元素顶部对齐;
center表示将视口的中间和元素的中间对齐;
end表示将视口的底部和元素底部对齐;
nearest表示就近对齐。
inline表示行内元素排列方向要滚动到的位置。对于默认的
writing-mode: horizontal-tb来说,就是水平方向。其值与
block类似。scrollIntoView 浏览器兼容性

最后我用的是
scrollIntoView, 问题完美解决。









