From 5238089e2f2acaca4fd2396d8ec3467ef4de0b2e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Mon, 7 Nov 2016 10:54:34 +0100 Subject: [PATCH 1/2] Initialize lastpos with start value --- animatedScrollTo.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/animatedScrollTo.js b/animatedScrollTo.js index bc7d0cb..20ab14f 100644 --- a/animatedScrollTo.js +++ b/animatedScrollTo.js @@ -13,7 +13,7 @@ change = to - start, animationStart = +new Date(); var animating = true; - var lastpos = null; + var lastpos = start; var animateScroll = function() { if (!animating) { @@ -22,16 +22,11 @@ requestAnimFrame(animateScroll); var now = +new Date(); var val = Math.floor(easeInOutQuad(now - animationStart, start, change, duration)); - if (lastpos) { - if (lastpos === element.scrollTop) { - lastpos = val; - element.scrollTop = val; - } else { - animating = false; - } - } else { + if (lastpos === element.scrollTop) { lastpos = val; element.scrollTop = val; + } else { + animating = false; } if (now > animationStart + duration) { element.scrollTop = to; From 0c9375a3535f597ddb0e041f7582944c0e8ff58f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Mon, 7 Nov 2016 10:59:16 +0100 Subject: [PATCH 2/2] Fixed issue with Chrome zoom --- animatedScrollTo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/animatedScrollTo.js b/animatedScrollTo.js index 20ab14f..a1005fb 100644 --- a/animatedScrollTo.js +++ b/animatedScrollTo.js @@ -23,8 +23,8 @@ var now = +new Date(); var val = Math.floor(easeInOutQuad(now - animationStart, start, change, duration)); if (lastpos === element.scrollTop) { - lastpos = val; element.scrollTop = val; + lastpos = element.scrollTop; } else { animating = false; }