返回顶部动画
2020-01-03 本文已影响0人
web佳
backTop(type) {
let timer = null;
const { htmlSize } = this;
console.log(htmlSize);
cancelAnimationFrame(timer);
timer = requestAnimationFrame(function fn() {
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
console.log(scrollTop);
if (scrollTop > 0) {
const gap = scrollTop - htmlSize;
document.body.scrollTop = gap;
document.documentElement.scrollTop = gap;
timer = requestAnimationFrame(fn);
} else {
cancelAnimationFrame(timer);
}
});
},