Skip to content

Commit adcccaa

Browse files
koenpuntkswedberg
authored andcommitted
Ensure variable [scrollDir]() is used, not scrollTop(). Use Math.ab() instead of multiply by -1 if negative.
1 parent ba978e1 commit adcccaa

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

jquery.smooth-scroll.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Smooth Scroll - v1.5.6 - 2015-09-08
2+
* jQuery Smooth Scroll - v1.5.6 - 2015-12-14
33
* https://github.com/kswedberg/jquery-smooth-scroll
44
* Copyright (c) 2015 Karl Swedberg
55
* Licensed MIT (https://github.com/kswedberg/jquery-smooth-scroll/blob/master/LICENSE-MIT)
@@ -231,12 +231,9 @@
231231
// automatically calculate the speed of the scroll based on distance / coefficient
232232
if (speed === 'auto') {
233233

234-
// $scroller.scrollTop() is position before scroll, aniProps[scrollDir] is position after
234+
// $scroller[scrollDir]() is position before scroll, aniProps[scrollDir] is position after
235235
// When delta is greater, speed will be greater.
236-
delta = aniProps[scrollDir] - $scroller.scrollTop();
237-
if(delta < 0) {
238-
delta *= -1;
239-
}
236+
delta = Math.abs(aniProps[scrollDir] - $scroller[scrollDir]());
240237

241238
// Divide the delta by the coefficient
242239
speed = delta / opts.autoCoefficient;

jquery.smooth-scroll.min.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"grunt": "~0.4.0",
3131
"grunt-contrib-concat": "~0.5.0",
3232
"grunt-contrib-jshint": "~0.1.1",
33-
"grunt-contrib-uglify": "~0.1.1",
33+
"grunt-contrib-uglify": "~0.2.0",
3434
"grunt-contrib-watch": "~0.3.1",
3535
"grunt-shell": "~0.2",
3636
"grunt-version": "~0.1.1",

src/jquery.smooth-scroll.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,9 @@
212212
// automatically calculate the speed of the scroll based on distance / coefficient
213213
if (speed === 'auto') {
214214

215-
// $scroller.scrollTop() is position before scroll, aniProps[scrollDir] is position after
215+
// $scroller[scrollDir]() is position before scroll, aniProps[scrollDir] is position after
216216
// When delta is greater, speed will be greater.
217-
delta = aniProps[scrollDir] - $scroller.scrollTop();
218-
if(delta < 0) {
219-
delta *= -1;
220-
}
217+
delta = Math.abs(aniProps[scrollDir] - $scroller[scrollDir]());
221218

222219
// Divide the delta by the coefficient
223220
speed = delta / opts.autoCoefficient;

0 commit comments

Comments
 (0)