1
- /*! Smooth Scroll - v1.4.5 - 2012-07-22
1
+ /*! Smooth Scroll - v1.4.6 - 2012-08-23
2
2
* Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
3
3
4
4
( function ( $ ) {
5
5
6
- var version = '1.4.5 ' ,
6
+ var version = '1.4.6 ' ,
7
7
defaults = {
8
8
exclude : [ ] ,
9
9
excludeWithin :[ ] ,
@@ -34,15 +34,28 @@ var version = '1.4.5',
34
34
// if scroll(Top|Left) === 0, nudge the element 1px and see if it moves
35
35
el [ dir ] ( 1 ) ;
36
36
scrolled = el [ dir ] ( ) > 0 ;
37
- // then put it back, of course
38
- el [ dir ] ( 0 ) ;
39
37
if ( scrolled ) {
40
38
scrollable . push ( this ) ;
41
39
}
40
+ // then put it back, of course
41
+ el [ dir ] ( 0 ) ;
42
42
}
43
43
} ) ;
44
44
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 ) {
46
59
scrollable = [ scrollable [ 0 ] ] ;
47
60
}
48
61
@@ -107,7 +120,6 @@ $.fn.extend({
107
120
} ) ;
108
121
109
122
return this ;
110
-
111
123
}
112
124
} ) ;
113
125
@@ -118,7 +130,6 @@ $.smoothScroll = function(options, px) {
118
130
scrollDir = 'scrollTop' ,
119
131
aniProps = { } ,
120
132
aniOpts = { } ,
121
- useScrollTo = false ,
122
133
scrollprops = [ ] ;
123
134
124
135
if ( typeof options === 'number' ) {
@@ -147,48 +158,40 @@ $.smoothScroll = function(options, px) {
147
158
scrollerOffset = $scroller [ scrollDir ] ( ) ;
148
159
} else {
149
160
$scroller = $ ( 'html, body' ) . firstScrollable ( ) ;
150
- useScrollTo = isTouch && 'scrollTo' in window ;
151
161
}
152
162
153
163
aniProps [ scrollDir ] = scrollTargetOffset + scrollerOffset + opts . offset ;
154
164
155
165
opts . beforeScroll . call ( $scroller , opts ) ;
156
166
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 ;
161
168
162
- } else {
163
- speed = opts . speed ;
169
+ // automatically calculate the speed of the scroll based on distance / coefficient
170
+ if ( speed === 'auto' ) {
164
171
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 ( ) ;
167
174
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
+ }
170
178
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 ) ;
173
184
}
185
+ } ;
174
186
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
+ }
186
190
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 ) ;
192
195
}
193
196
} ;
194
197
0 commit comments