From bd573bb0f063469ffc7a0b25692677634778df51 Mon Sep 17 00:00:00 2001 From: tu-vu-duy Date: Wed, 24 Oct 2012 23:38:56 +0700 Subject: [PATCH] Fix value of 'speed' when set default is 'auto' --- jquery.smooth-scroll.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jquery.smooth-scroll.js b/jquery.smooth-scroll.js index 7872c40..20a34b6 100644 --- a/jquery.smooth-scroll.js +++ b/jquery.smooth-scroll.js @@ -169,11 +169,15 @@ $.smoothScroll = function(options, px) { // automatically calculate the speed of the scroll based on distance / coefficient if (speed === 'auto') { - // if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead - speed = aniProps[scrollDir] || $scroller.scrollTop(); + // $scroller.scrollTop() is brefore scroll, aniProps[scrollDir] is after scroll + //'delta' is value changing. When 'delta' bigger, then 'speed' will be larger same and vice versa. + var delta = aniProps[scrollDir] - $scroller.scrollTop(); + if(delta < 0) { + delta *= -1; + } // divide the speed by the coefficient - speed = speed / opts.autoCoefficent; + speed = delta / opts.autoCoefficent; } aniOpts = {