Skip to main content

goToTop

goToTop 平滑滚动到顶部

🔖 更新版本

v0.0.31

🍱 参数

🔥 返回值

🚀 示例

import { goToTop } from 'atools-js';

goToTop();

💡 源码

source code
/atools/_browser/goToTop.ts
export const goToTop = (): void => {
const c = document?.documentElement?.scrollTop ?? document?.body?.scrollTop;
if (c > 0) {
window.requestAnimationFrame(goToTop);
window.scrollTo(0, c - c / 8);
}
}