1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| function scrollTopBy(endTop,easing){ var beginTop = $(window).scrollTop(); var range = endTop - beginTop; var start = 0; var step = 20; var total = Math.abs(Math.ceil(range / step)); var timer = null; function startScroll(){ if(start <= total){ var top = Math.round(easing(start,beginTop,range,total)); window.scrollTo(0,top); start ++; timer = setTimeout(function(){ startScroll(); },13); }else{ clearTimeout(timer); timer = null; } } startScroll(); } var endTop = $(window).scrollTop(); scrollTopBy(endTop,function(t, b, c, d) { return c*t/d + b; });
|