1
1
/*!
2
- * jQuery Smooth Scroll Plugin v1.4.1
2
+ * jQuery Smooth Scroll Plugin v1.4.2
3
3
*
4
- * Date: Tue Nov 15 14:24:14 2011 EST
4
+ * Date: Tue Feb 14 17:34:02 2012 EST
5
5
* Requires: jQuery v1.3+
6
6
*
7
7
* Copyright 2010, Karl Swedberg
16
16
17
17
( function ( $ ) {
18
18
19
- var version = '1.4.1 ' ,
19
+ var version = '1.4.2 ' ,
20
20
defaults = {
21
21
exclude : [ ] ,
22
22
excludeWithin :[ ] ,
@@ -30,6 +30,7 @@ var version = '1.4.1',
30
30
easing : 'swing' ,
31
31
speed : 400
32
32
} ,
33
+
33
34
locationPath = filterPath ( location . pathname ) ,
34
35
getScrollable = function ( opts ) {
35
36
var scrollable = [ ] ,
@@ -60,7 +61,8 @@ var version = '1.4.1',
60
61
}
61
62
62
63
return scrollable ;
63
- } ;
64
+ } ,
65
+ isTouch = 'ontouchend' in document ;
64
66
65
67
$ . fn . extend ( {
66
68
scrollable : function ( dir ) {
@@ -123,7 +125,9 @@ $.smoothScroll = function(options, px) {
123
125
scrollerOffset = 0 ,
124
126
offPos = 'offset' ,
125
127
scrollDir = 'scrollTop' ,
126
- aniprops = { } ;
128
+ aniprops = { } ,
129
+ useScrollTo = false ,
130
+ scrollprops = [ ] ;
127
131
128
132
if ( typeof options === 'number' ) {
129
133
opts = $ . fn . smoothScroll . defaults ;
@@ -150,6 +154,7 @@ $.smoothScroll = function(options, px) {
150
154
scrollerOffset = $scroller [ scrollDir ] ( ) ;
151
155
} else {
152
156
$scroller = $ ( 'html, body' ) . firstScrollable ( ) ;
157
+ useScrollTo = isTouch && 'scrollTo' in window ;
153
158
}
154
159
155
160
aniprops [ scrollDir ] = scrollTargetOffset + scrollerOffset + opts . offset ;
@@ -158,16 +163,21 @@ $.smoothScroll = function(options, px) {
158
163
opts . beforeScroll . call ( $scroller , opts ) ;
159
164
}
160
165
161
- $scroller . animate ( aniprops ,
162
- {
163
- duration : opts . speed ,
164
- easing : opts . easing ,
165
- complete : function ( ) {
166
- if ( opts . afterScroll && $ . isFunction ( opts . afterScroll ) ) {
167
- opts . afterScroll . call ( opts . link , opts ) ;
166
+ if ( useScrollTo ) {
167
+ scrollprops = ( opts . direction == 'left' ) ? [ aniprops [ scrollDir ] , 0 ] : [ 0 , aniprops [ scrollDir ] ] ;
168
+ window . scrollTo . apply ( window , scrollprops ) ;
169
+ } else {
170
+ $scroller . animate ( aniprops ,
171
+ {
172
+ duration : opts . speed ,
173
+ easing : opts . easing ,
174
+ complete : function ( ) {
175
+ if ( opts . afterScroll && $ . isFunction ( opts . afterScroll ) ) {
176
+ opts . afterScroll . call ( opts . link , opts ) ;
177
+ }
168
178
}
169
- }
170
- } ) ;
179
+ } ) ;
180
+ }
171
181
172
182
} ;
173
183
0 commit comments