纯js实现页面返回顶部的动画

时间:2021-06-16 10:06:49

啥也不说了,直接上代码

1    var scrollTop = document.body.scrollTop;
2    document.body.style.marginTop = -scrollTop + 'px';
3    document.body.scrollTop = 0;
4    document.body.style.transition = 'all 1s ease-in-out';
5    document.body.style.marginTop = 0;
6    setTimeout(function () { document.body.style.transition = 'none'; }, 1000);

需要的请随意拿走....