Skip to content

Commit 84ef112

Browse files
committed
Added an option to have an automatic scroll speed. (can be adjusted by auto_coeff)
1 parent 1aba5d4 commit 84ef112

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jquery.smooth-scroll.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var version = '1.4.4',
2828
beforeScroll: function() {}, // fn(opts) function to be called before scrolling occurs. "this" is the element(s) being scrolled
2929
afterScroll: function() {}, // fn(opts) function to be called after scrolling occurs. "this" is the triggering element
3030
easing: 'swing',
31-
speed: 400
31+
speed: 400,
32+
auto_coeff: 2 // coefficient for "auto" speed
3233
},
3334

3435
getScrollable = function(opts) {
@@ -168,6 +169,18 @@ $.smoothScroll = function(options, px) {
168169
opts.afterScroll.call(opts.link, opts);
169170

170171
} else {
172+
var speed;
173+
if(opts.speed === 'auto') {
174+
if(aniprops[scrollDir] === 0) {
175+
speed = $('html').scrollTop();
176+
} else {
177+
speed = aniprops[scrollDir];
178+
}
179+
speed = speed / opts.auto_coeff;
180+
} else {
181+
speed = opts.speed;
182+
}
183+
171184
$scroller.animate(aniprops,
172185
{
173186
duration: opts.speed,

0 commit comments

Comments
 (0)