Skip to content

Commit ac380e3

Browse files
committed
Release 1.4.6
1 parent 6deb42c commit ac380e3

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

jquery.smooth-scroll.js

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*! Smooth Scroll - v1.4.5 - 2012-07-22
1+
/*! Smooth Scroll - v1.4.6 - 2012-08-23
22
* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
33

44
(function($) {
55

6-
var version = '1.4.5',
6+
var version = '1.4.6',
77
defaults = {
88
exclude: [],
99
excludeWithin:[],
@@ -34,15 +34,28 @@ var version = '1.4.5',
3434
// if scroll(Top|Left) === 0, nudge the element 1px and see if it moves
3535
el[dir](1);
3636
scrolled = el[dir]() > 0;
37-
// then put it back, of course
38-
el[dir](0);
3937
if ( scrolled ) {
4038
scrollable.push(this);
4139
}
40+
// then put it back, of course
41+
el[dir](0);
4242
}
4343
});
4444

45-
if ( opts.el === 'first' && scrollable.length ) {
45+
// If no scrollable elements, fall back to <body>,
46+
// if it's in the jQuery collection
47+
// (doing this because Safari sets scrollTop async,
48+
// so can't set it to 1 and immediately get the value.)
49+
if (!scrollable.length) {
50+
this.each(function(index) {
51+
if (this.nodeName === 'BODY') {
52+
scrollable = [this];
53+
}
54+
});
55+
}
56+
57+
// Use the first scrollable element if we're calling firstScrollable()
58+
if ( opts.el === 'first' && scrollable.length > 1 ) {
4659
scrollable = [ scrollable[0] ];
4760
}
4861

@@ -107,7 +120,6 @@ $.fn.extend({
107120
});
108121

109122
return this;
110-
111123
}
112124
});
113125

@@ -118,7 +130,6 @@ $.smoothScroll = function(options, px) {
118130
scrollDir = 'scrollTop',
119131
aniProps = {},
120132
aniOpts = {},
121-
useScrollTo = false,
122133
scrollprops = [];
123134

124135
if ( typeof options === 'number') {
@@ -147,48 +158,40 @@ $.smoothScroll = function(options, px) {
147158
scrollerOffset = $scroller[scrollDir]();
148159
} else {
149160
$scroller = $('html, body').firstScrollable();
150-
useScrollTo = isTouch && 'scrollTo' in window;
151161
}
152162

153163
aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
154164

155165
opts.beforeScroll.call($scroller, opts);
156166

157-
if ( useScrollTo ) {
158-
scrollprops = (opts.direction == 'left') ? [aniProps[scrollDir], 0] : [0, aniProps[scrollDir]];
159-
window.scrollTo.apply(window, scrollprops);
160-
opts.afterScroll.call(opts.link, opts);
167+
speed = opts.speed;
161168

162-
} else {
163-
speed = opts.speed;
169+
// automatically calculate the speed of the scroll based on distance / coefficient
170+
if (speed === 'auto') {
164171

165-
// automatically calculate the speed of the scroll based on distance / coefficient
166-
if (speed === 'auto') {
172+
// if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
173+
speed = aniProps[scrollDir] || $scroller.scrollTop();
167174

168-
// if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
169-
speed = aniProps[scrollDir] || $scroller.scrollTop();
175+
// divide the speed by the coefficient
176+
speed = speed / opts.autoCoefficent;
177+
}
170178

171-
// divide the speed by the coefficient
172-
speed = speed / opts.autoCoefficent;
179+
aniOpts = {
180+
duration: speed,
181+
easing: opts.easing,
182+
complete: function() {
183+
opts.afterScroll.call(opts.link, opts);
173184
}
185+
};
174186

175-
aniOpts = {
176-
duration: speed,
177-
easing: opts.easing,
178-
complete: function() {
179-
opts.afterScroll.call(opts.link, opts);
180-
}
181-
};
182-
183-
if (opts.step) {
184-
aniOpts.step = opts.step;
185-
}
187+
if (opts.step) {
188+
aniOpts.step = opts.step;
189+
}
186190

187-
if ( $(document).height() > $(window).height ) {
188-
$scroller.stop().animate(aniProps, aniOpts);
189-
} else {
190-
opts.afterScroll.call(opts.link, opts);
191-
}
191+
if ($scroller.length) {
192+
$scroller.stop().animate(aniProps, aniOpts);
193+
} else {
194+
opts.afterScroll.call(opts.link, opts);
192195
}
193196
};
194197

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
@@ -2,7 +2,7 @@
22
"name": "jquery.smooth-scroll",
33
"title": "Smooth Scroll",
44
"description": "Easy implementation of smooth scrolling for same-page links",
5-
"version": "1.4.5",
5+
"version": "1.4.6",
66
"homepage": "",
77
"author": {
88
"name": "Karl Swedberg",

0 commit comments

Comments
 (0)