Skip to content

Commit 3cd3e86

Browse files
committed
simplified auto /coefficient speed,
fixing the scrolling element used, and put the correct value in for the .animate() duration option
1 parent 8abf1e7 commit 3cd3e86

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

jquery.smooth-scroll.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*!
2-
* jQuery Smooth Scroll Plugin v1.4.4
2+
* jQuery Smooth Scroll Plugin v1.4.5
33
*
4-
* Date: Mon Feb 20 09:04:54 2012 EST
4+
* Date: Sun Mar 11 18:17:42 2012 EDT
55
* Requires: jQuery v1.3+
66
*
7-
* Copyright 2010, Karl Swedberg
7+
* Copyright 2012, Karl Swedberg
88
* Dual licensed under the MIT and GPL licenses (just like jQuery):
99
* http://www.opensource.org/licenses/mit-license.php
1010
* http://www.gnu.org/licenses/gpl.html
@@ -29,7 +29,7 @@ var version = '1.4.4',
2929
afterScroll: function() {}, // fn(opts) function to be called after scrolling occurs. "this" is the triggering element
3030
easing: 'swing',
3131
speed: 400,
32-
auto_coeff: 2 // coefficient for "auto" speed
32+
autoCoefficent: 2 // coefficient for "auto" speed
3333
},
3434

3535
getScrollable = function(opts) {
@@ -123,7 +123,7 @@ $.fn.extend({
123123
});
124124

125125
$.smoothScroll = function(options, px) {
126-
var opts, $scroller, scrollTargetOffset,
126+
var opts, $scroller, scrollTargetOffset, speed,
127127
scrollerOffset = 0,
128128
offPos = 'offset',
129129
scrollDir = 'scrollTop',
@@ -169,21 +169,19 @@ $.smoothScroll = function(options, px) {
169169
opts.afterScroll.call(opts.link, opts);
170170

171171
} 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;
172+
speed = opts.speed;
173+
174+
// automatically calculate the speed of the scroll based on distance / coefficient
175+
if (speed === 'auto') {
176+
// if aniprops[scrollDir] == 0 then we'll use scrollTop() value instead
177+
speed = aniprops[scrollDir] || $scroller.scrollTop();
178+
// divide the speed by the coefficient
179+
speed = speed / opts.autoCoefficent;
182180
}
183181

184182
$scroller.animate(aniprops,
185183
{
186-
duration: opts.speed,
184+
duration: speed,
187185
easing: opts.easing,
188186
complete: function() {
189187
opts.afterScroll.call(opts.link, opts);

jquery.smooth-scroll.min.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)