Skip to content

Commit

Permalink
fix: Safari 平滑滚动无法打断, thank @Reedo0910
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanDecode committed May 1, 2020
1 parent 4931ecb commit 2f105c8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assets/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,21 @@ VOID_Lazyload = {
VOID_SmoothScroller = {
target: null,
SMOOTH: 15,
raf: null,

move: function () {
var cur = document.documentElement.scrollTop;
var step = Math.ceil(Math.abs(VOID_SmoothScroller.target - cur) / VOID_SmoothScroller.SMOOTH);

if (Math.abs(VOID_SmoothScroller.target - cur) < 1) {
VOID_SmoothScroller.removeEventListener();
cancelAnimationFrame(VOID_SmoothScroller.raf);
return;
}

cur >= VOID_SmoothScroller.target ? cur -= step : cur += step;
document.documentElement.scrollTop = cur;
requestAnimationFrame(VOID_SmoothScroller.move);
VOID_SmoothScroller.raf = requestAnimationFrame(VOID_SmoothScroller.move);
},

addEventListener: function () {
Expand Down

0 comments on commit 2f105c8

Please sign in to comment.