页面刷新后不定位到之前的滚动位置

177 阅读1分钟

原文: zhangxinxu from www.zhangxinxu.com/wordpress/?… 鑫空间-鑫生活

页面刷新后浏览器会自动滚动到之前的位置,而不是停留在scrollTop为0的顶端。

如何禁止掉这个功能呢?

其实浏览器提供了原生API:

history.scrollRestoration = 'manual';