- commit
- a59019b33f658cbb8bb24cc992c4109018433db7
- parent
- 47b0926617f68e9cd140523e5a39405d68cb3698
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2016-11-18 18:00
nicer easing
Diffstat
| M | smooth-scroll.js | 10 | +++++++--- |
1 files changed, 7 insertions, 3 deletions
diff --git a/smooth-scroll.js b/smooth-scroll.js
@@ -24,14 +24,18 @@ 24 24 window.requestAnimationFrame(step); 25 25 }; 26 2627 -1 var smoothScrollTo = function(endY, duration) {-1 27 var cubicInOut = function(t) { -1 28 return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1; -1 29 }; -1 30 -1 31 var smoothScrollTo = function(endY, duration, easing) { 28 32 duration = duration || 400; -1 33 easing = easing || cubicInOut; 29 34 30 35 var startY = window.scrollY; 31 36 32 37 animate(function(progress) {33 -1 // var f = Math.sin(Math.PI * (progress - 0.5)) / 2 + 0.5;34 -1 var f = (3 - 2 * progress) * progress * progress;-1 38 var f = easing(progress); 35 39 window.scrollTo(0, startY * (1 - f) + endY * f); 36 40 }, duration); 37 41 };