@@ -47,7 +47,8 @@ ParallaxJS.prototype = {
47
47
if ( style . display === 'none' ) return
48
48
49
49
const height = mod . absY ? window . innerHeight : el . clientHeight || el . scrollHeight
50
-
50
+ const width = mod . absY ? window . innerWidth : el . clientWidth || el . scrollWidth
51
+
51
52
const cl = this . os . className
52
53
if ( typeof cl === 'string' ) {
53
54
el . className = `${ el . className } ${ cl } ` . trim ( )
@@ -61,6 +62,7 @@ ParallaxJS.prototype = {
61
62
arg,
62
63
mod,
63
64
height,
65
+ width,
64
66
count : 0
65
67
} )
66
68
} ,
@@ -71,6 +73,8 @@ ParallaxJS.prototype = {
71
73
const n = t . currentStyle || window . getComputedStyle ( t )
72
74
73
75
item . height = item . mod . absY ? window . innerHeight : t . clientHeight || t . scrollHeight
76
+ item . width = item . mod . absX ? window . innerWidth : t . clientWidth || t . scrollWidth
77
+
74
78
if ( t . offsetParent !== null )
75
79
item . iOT = t . offsetTop + t . offsetParent . offsetTop - parseInt ( n . marginTop )
76
80
@@ -90,15 +94,18 @@ ParallaxJS.prototype = {
90
94
91
95
const sT = this . container ? this . container . scrollTop : window . scrollY || window . pageYOffset
92
96
const wH = window . innerHeight
97
+ const wW = window . innerWidth
93
98
94
99
this . items . forEach ( ( item ) => {
95
100
const elH = item . height
101
+ const elW = item . width
96
102
const offset = item . iOT * - 1 * item . value
97
103
const pos = ( ( ( sT + wH ) - ( elH / 2 ) - ( wH / 2 ) ) * item . value ) + offset
98
-
104
+ const posY = ( ( ( sT + wW ) - ( elW / 2 ) - ( wW / 2 ) ) * item . value ) + offset
105
+
99
106
window . requestAnimationFrame ( ( ) => {
100
107
const cx = item . mod . centerX ? '-50%' : '0px'
101
- const props = `translate3d(${ cx } ,${ pos . toFixed ( 3 ) } px,0px)`
108
+ const props = ! item . mod . horizontal ? `translate3d(${ cx } ,${ pos . toFixed ( 3 ) } px,0px)` : `translate3d( ${ posY . toFixed ( 3 ) } px,0px ,0px)`
102
109
item . el . style [ this . tProp ] = props
103
110
} )
104
111
} )
0 commit comments