@@ -31,15 +31,28 @@ var version = '@VERSION',
31
31
// if scroll(Top|Left) === 0, nudge the element 1px and see if it moves
32
32
el [ dir ] ( 1 ) ;
33
33
scrolled = el [ dir ] ( ) > 0 ;
34
- // then put it back, of course
35
- el [ dir ] ( 0 ) ;
36
34
if ( scrolled ) {
37
35
scrollable . push ( this ) ;
38
36
}
37
+ // then put it back, of course
38
+ el [ dir ] ( 0 ) ;
39
39
}
40
40
} ) ;
41
41
42
- if ( opts . el === 'first' && scrollable . length ) {
42
+ // If no scrollable elements, fall back to <body>,
43
+ // if it's in the jQuery collection
44
+ // (doing this because Safari sets scrollTop async,
45
+ // so can't set it to 1 and immediately get the value.)
46
+ if ( ! scrollable . length ) {
47
+ this . each ( function ( index ) {
48
+ if ( this . nodeName === 'BODY' ) {
49
+ scrollable = [ this ] ;
50
+ }
51
+ } ) ;
52
+ }
53
+
54
+ // Use the first scrollable element if we're calling firstScrollable()
55
+ if ( opts . el === 'first' && scrollable . length > 1 ) {
43
56
scrollable = [ scrollable [ 0 ] ] ;
44
57
}
45
58
@@ -104,7 +117,6 @@ $.fn.extend({
104
117
} ) ;
105
118
106
119
return this ;
107
-
108
120
}
109
121
} ) ;
110
122
@@ -115,7 +127,6 @@ $.smoothScroll = function(options, px) {
115
127
scrollDir = 'scrollTop' ,
116
128
aniProps = { } ,
117
129
aniOpts = { } ,
118
- useScrollTo = false ,
119
130
scrollprops = [ ] ;
120
131
121
132
if ( typeof options === 'number' ) {
@@ -144,44 +155,40 @@ $.smoothScroll = function(options, px) {
144
155
scrollerOffset = $scroller [ scrollDir ] ( ) ;
145
156
} else {
146
157
$scroller = $ ( 'html, body' ) . firstScrollable ( ) ;
147
- useScrollTo = isTouch && 'scrollTo' in window ;
148
158
}
149
159
150
160
aniProps [ scrollDir ] = scrollTargetOffset + scrollerOffset + opts . offset ;
151
161
152
162
opts . beforeScroll . call ( $scroller , opts ) ;
153
163
154
- if ( useScrollTo ) {
155
- scrollprops = ( opts . direction == 'left' ) ? [ aniProps [ scrollDir ] , 0 ] : [ 0 , aniProps [ scrollDir ] ] ;
156
- window . scrollTo . apply ( window , scrollprops ) ;
157
- opts . afterScroll . call ( opts . link , opts ) ;
164
+ speed = opts . speed ;
158
165
159
- } else {
160
- speed = opts . speed ;
166
+ // automatically calculate the speed of the scroll based on distance / coefficient
167
+ if ( speed === 'auto' ) {
161
168
162
- // automatically calculate the speed of the scroll based on distance / coefficient
163
- if ( speed === 'auto' ) {
169
+ // if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
170
+ speed = aniProps [ scrollDir ] || $scroller . scrollTop ( ) ;
164
171
165
- // if aniProps[scrollDir] == 0 then we'll use scrollTop() value instead
166
- speed = aniProps [ scrollDir ] || $scroller . scrollTop ( ) ;
172
+ // divide the speed by the coefficient
173
+ speed = speed / opts . autoCoefficent ;
174
+ }
167
175
168
- // divide the speed by the coefficient
169
- speed = speed / opts . autoCoefficent ;
176
+ aniOpts = {
177
+ duration : speed ,
178
+ easing : opts . easing ,
179
+ complete : function ( ) {
180
+ opts . afterScroll . call ( opts . link , opts ) ;
170
181
}
182
+ } ;
171
183
172
- aniOpts = {
173
- duration : speed ,
174
- easing : opts . easing ,
175
- complete : function ( ) {
176
- opts . afterScroll . call ( opts . link , opts ) ;
177
- }
178
- } ;
179
-
180
- if ( opts . step ) {
181
- aniOpts . step = opts . step ;
182
- }
184
+ if ( opts . step ) {
185
+ aniOpts . step = opts . step ;
186
+ }
183
187
188
+ if ( $scroller . length ) {
184
189
$scroller . stop ( ) . animate ( aniProps , aniOpts ) ;
190
+ } else {
191
+ opts . afterScroll . call ( opts . link , opts ) ;
185
192
}
186
193
} ;
187
194
0 commit comments