scrollIntoView()的用法:
element.scrollIntoView({behavior: “instant”, block: “end”, inline: “nearest”});
三个可选参数:
behavior 可选
定义缓动动画, “auto”, “instant”, 或 “smooth” 之一。默认为 “auto”。
block 可选
“start”, “center”, “end”, 或 "nearest"之一。默认为 “start”。
inline 可选
“start”, “center”, “end”, 或 "nearest"之一。默认为 “nearest”。
scrollTo()的用法:
element.scrollTo({
top: 100,
left: 100,
behavior: ‘smooth’ // 定义缓动动画
});
平滑滚动到指定位置scrollIntoView()或者scrollTo()
最新推荐文章于 2024-02-20 16:31:40 发布