11/*!
2- * jQuery Smooth Scroll Plugin v1.4.1
2+ * jQuery Smooth Scroll Plugin v1.4.2
33 *
4- * Date: Tue Nov 15 14:24:14 2011 EST
4+ * Date: Tue Feb 14 17:34:02 2012 EST
55 * Requires: jQuery v1.3+
66 *
77 * Copyright 2010, Karl Swedberg
1616
1717( function ( $ ) {
1818
19- var version = '1.4.1 ' ,
19+ var version = '1.4.2 ' ,
2020 defaults = {
2121 exclude : [ ] ,
2222 excludeWithin :[ ] ,
@@ -30,6 +30,7 @@ var version = '1.4.1',
3030 easing : 'swing' ,
3131 speed : 400
3232 } ,
33+
3334 locationPath = filterPath ( location . pathname ) ,
3435 getScrollable = function ( opts ) {
3536 var scrollable = [ ] ,
@@ -60,7 +61,8 @@ var version = '1.4.1',
6061 }
6162
6263 return scrollable ;
63- } ;
64+ } ,
65+ isTouch = 'ontouchend' in document ;
6466
6567$ . fn . extend ( {
6668 scrollable : function ( dir ) {
@@ -123,7 +125,9 @@ $.smoothScroll = function(options, px) {
123125 scrollerOffset = 0 ,
124126 offPos = 'offset' ,
125127 scrollDir = 'scrollTop' ,
126- aniprops = { } ;
128+ aniprops = { } ,
129+ useScrollTo = false ,
130+ scrollprops = [ ] ;
127131
128132 if ( typeof options === 'number' ) {
129133 opts = $ . fn . smoothScroll . defaults ;
@@ -150,6 +154,7 @@ $.smoothScroll = function(options, px) {
150154 scrollerOffset = $scroller [ scrollDir ] ( ) ;
151155 } else {
152156 $scroller = $ ( 'html, body' ) . firstScrollable ( ) ;
157+ useScrollTo = isTouch && 'scrollTo' in window ;
153158 }
154159
155160 aniprops [ scrollDir ] = scrollTargetOffset + scrollerOffset + opts . offset ;
@@ -158,16 +163,21 @@ $.smoothScroll = function(options, px) {
158163 opts . beforeScroll . call ( $scroller , opts ) ;
159164 }
160165
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+ }
168178 }
169- }
170- } ) ;
179+ } ) ;
180+ }
171181
172182} ;
173183
0 commit comments