@@ -38,7 +38,7 @@ jcparallax.Viewport = function(el, options, layerOptions)
38
38
} ;
39
39
40
40
// determine layer movement ranges if set to automatic
41
- this . options = jcparallax . Viewport . _calcMovementRanges ( $ . extend ( true , defaults , options ) ) ;
41
+ this . options = jcparallax . Viewport . _inferMovementRanges ( $ . extend ( true , defaults , options ) ) ;
42
42
43
43
// set layer opts for passing on to child layers
44
44
this . layerOptions = layerOptions ;
@@ -81,7 +81,7 @@ $.extend(jcparallax.Viewport, {
81
81
* @param {object } options incoming options object
82
82
* @return the processed options
83
83
*/
84
- _calcMovementRanges : function ( options )
84
+ _inferMovementRanges : function ( options )
85
85
{
86
86
// set default range calculation callbacks
87
87
if ( options . movementRangeX === true || options . movementRangeY === true && ! $ . isFunction ( options . animHandler ) ) {
@@ -93,23 +93,23 @@ $.extend(jcparallax.Viewport, {
93
93
case 'background' :
94
94
case 'stretch' :
95
95
switch ( options . inputHandler ) {
96
- case 'mousemove' :
97
- options . movementRangeX = 'width' ;
98
- options . movementRangeY = 'height' ;
99
- break ;
100
96
case 'scroll' :
101
- options . movementRangeX = 'scrollWidth' ;
102
- options . movementRangeY = 'scrollHeight' ;
97
+ options . movementRangeX = jcparallax . Layer . rangeCalculators . scrollWidth ;
98
+ options . movementRangeY = jcparallax . Layer . rangeCalculators . scrollHeight ;
99
+ break ;
100
+ default :
101
+ options . movementRangeX = jcparallax . Layer . rangeCalculators . width ;
102
+ options . movementRangeY = jcparallax . Layer . rangeCalculators . height ;
103
103
break ;
104
104
}
105
105
break ;
106
106
case 'textShadow' :
107
- options . movementRangeX = ' fontSize' ;
108
- options . movementRangeY = ' lineHeight' ;
107
+ options . movementRangeX = jcparallax . Layer . rangeCalculators . fontSize ;
108
+ options . movementRangeY = jcparallax . Layer . rangeCalculators . lineHeight ;
109
109
break ;
110
110
case 'opacity' :
111
- options . movementRangeX = 0 ;
112
- options . movementRangeY = ' opacity' ;
111
+ options . movementRangeX = [ 0 , 0 ] ;
112
+ options . movementRangeY = jcparallax . Layer . rangeCalculators . opacity ;
113
113
break ;
114
114
}
115
115
}
@@ -146,7 +146,6 @@ $.extend(jcparallax.Viewport.prototype, {
146
146
bindEvent : function ( eventName , handler )
147
147
{
148
148
var that = this ;
149
-
150
149
eventName += jcparallax . eventNamespace ;
151
150
152
151
// detach old callback first if present
@@ -246,8 +245,8 @@ $.extend(jcparallax.Viewport.prototype, {
246
245
this . offsetY = offset . top ;
247
246
this . sizeX = this . element . width ( ) ;
248
247
this . sizeY = this . element . height ( ) ;
249
- this . scrollX = this . element . attr ( ' scrollWidth' ) ;
250
- this . scrollY = this . element . attr ( ' scrollHeight' ) ;
248
+ this . scrollX = this . element [ 0 ] . scrollWidth - this . sizeX ;
249
+ this . scrollY = this . element [ 0 ] . scrollHeight - this . sizeY ;
251
250
252
251
if ( this . layers ) {
253
252
$ . each ( this . layers , function ( i , layer ) {
@@ -294,7 +293,8 @@ jcparallax.Viewport.inputHandlers = {
294
293
var xPos = el . scrollLeft ( ) ,
295
294
yPos = el . scrollTop ( ) ;
296
295
297
- this . updateLastSamplePos ( xPos / this . scrollX , yPos / this . scrollY ) ;
296
+ // :NOTE: scroll offsets are often calculated smaller than the available space due to scrollbar space
297
+ this . updateLastSamplePos ( this . scrollX ? Math . min ( 1 , xPos / this . scrollX ) : 0 , this . scrollY ? Math . min ( 1 , yPos / this . scrollY ) : 0 ) ;
298
298
} ,
299
299
300
300
click : function ( el , evt )
0 commit comments