smooth-scroll

simple smooth scrolling in the browser
git clone https://git.ce9e.org/smooth-scroll.git

commit
5c3ceac2a26946b8c533a4a9b2b43d77687cc534
parent
2c9bc8c7044984a94b579ba02570986433d461ac
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2016-11-18 18:48
implement horizontal scrolling

Diffstat

M TODO 1 -
M smooth-scroll.js 9 ++++++---

2 files changed, 6 insertions, 4 deletions


diff --git a/TODO b/TODO

@@ -4,5 +4,4 @@
    4     4 
    5     5 # wontfix
    6     6 
    7    -1 -	horizontal scrolling
    8     7 -	other containers

diff --git a/smooth-scroll.js b/smooth-scroll.js

@@ -28,15 +28,18 @@
   28    28     return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
   29    29   };
   30    30 
   31    -1   var smoothScrollTo = function(endY, options) {
   -1    31   var smoothScrollTo = function(endX, endY, options) {
   32    32     var duration = (options || {}).duration || 400;
   33    33     var easing = (options || {}).easing || cubicInOut;
   34    34 
   -1    35     var startX = window.scrollX;
   35    36     var startY = window.scrollY;
   36    37 
   37    38     animate(function(progress) {
   38    39       var f = easing(progress);
   39    -1       window.scrollTo(0, startY * (1 - f) + endY * f);
   -1    40       var x = typeof endX === 'number' ? startX * (1 - f) + endX * f : startX;
   -1    41       var y = typeof endY === 'number' ? startY * (1 - f) + endY * f : startY;
   -1    42       window.scrollTo(x, y);
   40    43     }, duration);
   41    44   };
   42    45 
@@ -45,7 +48,7 @@
   45    48     var header = document.querySelector(headerSelector);
   46    49     var scrollY = document.querySelector(selector).offsetTop;
   47    50     if (header) scrollY -= header.getBoundingClientRect().height;
   48    -1     smoothScrollTo(scrollY, options);
   -1    51     smoothScrollTo(null, scrollY, options);
   49    52   };
   50    53 
   51    54   var init = function(options) {