浏览器默认会将之前浏览的页面的位置存下,下次刷新后会自动定位到之前浏览的位置,如果想不自动定位到之前浏览的位置,可以用history.scrollRestoration
history.scrollRestoration
可以将浏览器之前浏览的位置清空,再次刷新后会到页面的对顶端
if (history.scrollRestoration) {
history.scrollRestoration = 'manual';
}else {
console.log("不支持")
}
history.scrollRestoration
的值:
-
auto
默认值,表示滚动位置会被存储 -
manual
表示滚动的位置不会被存储
网友评论