1
- /*! iScroll v5.0.0-beta.1 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
1
+ /*! iScroll v5.0.0-beta.2 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
2
2
var IScroll = ( function ( window , document , Math ) {
3
3
4
4
var rAF = window . requestAnimationFrame ||
@@ -239,7 +239,6 @@ function IScroll (el, options) {
239
239
startX : 0 ,
240
240
startY : 0 ,
241
241
scrollY : true ,
242
- lockDirection : true ,
243
242
directionLockThreshold : 5 ,
244
243
momentum : true ,
245
244
@@ -272,7 +271,7 @@ function IScroll (el, options) {
272
271
this . options . scrollX = this . options . eventPassthrough == 'horizontal' ? false : this . options . scrollX ;
273
272
274
273
// With eventPassthrough we also need lockDirection mechanism
275
- this . options . lockDirection = this . options . lockDirection || this . options . eventPassthrough ;
274
+ this . options . freeScroll = this . options . freeScroll && ! this . options . eventPassthrough ;
276
275
this . options . directionLockThreshold = this . options . eventPassthrough ? 0 : this . options . directionLockThreshold ;
277
276
278
277
this . options . bounceEasing = typeof this . options . bounceEasing == 'string' ? utils . ease [ this . options . bounceEasing ] || utils . ease . circular : this . options . bounceEasing ;
@@ -303,7 +302,7 @@ function IScroll (el, options) {
303
302
}
304
303
305
304
IScroll . prototype = {
306
- version : '5.0.0-beta.1 ' ,
305
+ version : '5.0.0-beta.2 ' ,
307
306
308
307
_init : function ( ) {
309
308
this . _initEvents ( ) ;
@@ -417,13 +416,13 @@ IScroll.prototype = {
417
416
}
418
417
419
418
// If you are scrolling in one direction lock the other
420
- if ( ! this . directionLocked && this . options . lockDirection ) {
419
+ if ( ! this . directionLocked && ! this . options . freeScroll ) {
421
420
if ( absDistX > absDistY + this . options . directionLockThreshold ) {
422
421
this . directionLocked = 'h' ; // lock horizontally
423
422
} else if ( absDistY >= absDistX + this . options . directionLockThreshold ) {
424
423
this . directionLocked = 'v' ; // lock vertically
425
424
} else {
426
- this . directionLocked = 0 ; // no lock
425
+ this . directionLocked = 'n' ; // no lock
427
426
}
428
427
}
429
428
@@ -501,6 +500,8 @@ IScroll.prototype = {
501
500
time = 0 ,
502
501
easing = '' ;
503
502
503
+ this . scrollTo ( newX , newY ) ; // ensures that the last position is rounded
504
+
504
505
this . isInTransition = 0 ;
505
506
this . initiated = 0 ;
506
507
this . endTime = utils . getTime ( ) ;
@@ -594,6 +595,13 @@ IScroll.prototype = {
594
595
y = this . maxScrollY ;
595
596
}
596
597
598
+ if ( this . options . snap ) {
599
+ var snap = this . _nearestSnap ( x , y ) ;
600
+ this . currentPage = snap ;
601
+ x = snap . x ;
602
+ y = snap . y ;
603
+ }
604
+
597
605
this . scrollTo ( x , y , time , this . options . bounceEasing ) ;
598
606
599
607
return true ;
@@ -966,6 +974,10 @@ IScroll.prototype = {
966
974
this . pages = [ ] ;
967
975
this . currentPage = { } ;
968
976
977
+ if ( typeof this . options . snap == 'string' ) {
978
+ this . options . snap = this . scroller . querySelectorAll ( this . options . snap ) ;
979
+ }
980
+
969
981
this . on ( 'refresh' , function ( ) {
970
982
var i = 0 , l ,
971
983
m = 0 , n ,
@@ -979,12 +991,12 @@ IScroll.prototype = {
979
991
cx = Math . round ( stepX / 2 ) ;
980
992
cy = Math . round ( stepY / 2 ) ;
981
993
982
- while ( x >= - this . scrollerWidth ) {
994
+ while ( x > - this . scrollerWidth ) {
983
995
this . pages [ i ] = [ ] ;
984
996
l = 0 ;
985
997
y = 0 ;
986
998
987
- while ( y >= - this . scrollerHeight ) {
999
+ while ( y > - this . scrollerHeight ) {
988
1000
this . pages [ i ] [ l ] = {
989
1001
x : Math . max ( x , this . maxScrollX ) ,
990
1002
y : Math . max ( y , this . maxScrollY ) ,
@@ -1005,7 +1017,7 @@ IScroll.prototype = {
1005
1017
n = - 1 ;
1006
1018
1007
1019
for ( ; i < l ; i ++ ) {
1008
- if ( el [ i ] . offsetLeft === 0 ) {
1020
+ if ( i === 0 || el [ i ] . offsetLeft < el [ i - 1 ] . offsetLeft ) {
1009
1021
m = 0 ;
1010
1022
n ++ ;
1011
1023
}
@@ -1050,6 +1062,18 @@ IScroll.prototype = {
1050
1062
return this . currentPage ;
1051
1063
}
1052
1064
1065
+ if ( x > 0 ) {
1066
+ x = 0 ;
1067
+ } else if ( x < this . maxScrollX ) {
1068
+ x = this . maxScrollX ;
1069
+ }
1070
+
1071
+ if ( y > 0 ) {
1072
+ y = 0 ;
1073
+ } else if ( y < this . maxScrollY ) {
1074
+ y = this . maxScrollY ;
1075
+ }
1076
+
1053
1077
for ( ; i < l ; i ++ ) {
1054
1078
if ( x >= this . pages [ i ] [ 0 ] . cx ) {
1055
1079
x = this . pages [ i ] [ 0 ] . x ;
@@ -1101,7 +1125,7 @@ IScroll.prototype = {
1101
1125
goToPage : function ( x , y , time , easing ) {
1102
1126
if ( x >= this . pages . length ) {
1103
1127
x = this . pages . length - 1 ;
1104
- } else if ( x < 0 ) {
1128
+ } else if ( x < 0 ) {
1105
1129
x = 0 ;
1106
1130
}
1107
1131
@@ -1135,8 +1159,12 @@ IScroll.prototype = {
1135
1159
var x = this . currentPage . pageX ,
1136
1160
y = this . currentPage . pageY ;
1137
1161
1138
- x += this . hasHorizontalScroll ? 1 : 0 ;
1139
- y += this . hasVericalScroll ? 1 : 0 ;
1162
+ x ++ ;
1163
+
1164
+ if ( x >= this . pages . length && this . hasVericalScroll ) {
1165
+ x = 0 ;
1166
+ y ++ ;
1167
+ }
1140
1168
1141
1169
this . goToPage ( x , y , time , easing ) ;
1142
1170
} ,
@@ -1145,8 +1173,12 @@ IScroll.prototype = {
1145
1173
var x = this . currentPage . pageX ,
1146
1174
y = this . currentPage . pageY ;
1147
1175
1148
- x -= this . hasHorizontalScroll ? 1 : 0 ;
1149
- y -= this . hasVericalScroll ? 1 : 0 ;
1176
+ x -- ;
1177
+
1178
+ if ( x < 0 && this . hasVericalScroll ) {
1179
+ x = 0 ;
1180
+ y -- ;
1181
+ }
1150
1182
1151
1183
this . goToPage ( x , y , time , easing ) ;
1152
1184
} ,
0 commit comments