@@ -53,7 +53,8 @@ ParallaxJS.prototype = {
53
53
if ( style . display === 'none' ) return
54
54
55
55
const height = mod . absY ? window . innerHeight : el . clientHeight || el . scrollHeight
56
-
56
+ const width = mod . absY ? window . innerWidth : el . clientWidth || el . scrollWidth
57
+
57
58
const cl = this . os . className
58
59
if ( typeof cl === 'string' ) {
59
60
el . className = `${ el . className } ${ cl } ` . trim ( )
@@ -67,6 +68,7 @@ ParallaxJS.prototype = {
67
68
arg,
68
69
mod,
69
70
height,
71
+ width,
70
72
count : 0
71
73
} )
72
74
} ,
@@ -77,6 +79,8 @@ ParallaxJS.prototype = {
77
79
const n = t . currentStyle || window . getComputedStyle ( t )
78
80
79
81
item . height = item . mod . absY ? window . innerHeight : t . clientHeight || t . scrollHeight
82
+ item . width = item . mod . absX ? window . innerWidth : t . clientWidth || t . scrollWidth
83
+
80
84
if ( t . offsetParent !== null )
81
85
item . iOT = t . offsetTop + t . offsetParent . offsetTop - parseInt ( n . marginTop )
82
86
@@ -96,15 +100,18 @@ ParallaxJS.prototype = {
96
100
97
101
const sT = this . container ? this . container . scrollTop : window . scrollY || window . pageYOffset
98
102
const wH = window . innerHeight
103
+ const wW = window . innerWidth
99
104
100
105
this . items . forEach ( ( item ) => {
101
106
const elH = item . height
107
+ const elW = item . width
102
108
const offset = item . iOT * - 1 * item . value
103
109
const pos = ( ( ( sT + wH ) - ( elH / 2 ) - ( wH / 2 ) ) * item . value ) + offset
104
-
110
+ const posY = ( ( ( sT + wW ) - ( elW / 2 ) - ( wW / 2 ) ) * item . value ) + offset
111
+
105
112
window . requestAnimationFrame ( ( ) => {
106
113
const cx = item . mod . centerX ? '-50%' : '0px'
107
- const props = `translate3d(${ cx } ,${ pos . toFixed ( 3 ) } px,0px)`
114
+ const props = ! item . mod . horizontal ? `translate3d(${ cx } ,${ pos . toFixed ( 3 ) } px,0px)` : `translate3d( ${ posY . toFixed ( 3 ) } px,0px ,0px)`
108
115
item . el . style [ this . tProp ] = props
109
116
} )
110
117
} )
0 commit comments