@@ -91,12 +91,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
91
91
* attributes, if so set the elements parallax styles.
92
92
*/
93
93
function _updateAllElements ( { updateCache } = { } ) {
94
- elements . forEach ( element => {
95
- _updateElementPosition ( element ) ;
96
- if ( updateCache ) {
97
- element . setCachedAttributes ( view , scroll ) ;
98
- }
99
- } ) ;
94
+ if ( elements ) {
95
+ elements . forEach ( element => {
96
+ _updateElementPosition ( element ) ;
97
+ if ( updateCache ) {
98
+ element . setCachedAttributes ( view , scroll ) ;
99
+ }
100
+ } ) ;
101
+ }
100
102
// reset ticking so more animations can be called
101
103
ticking = false ;
102
104
}
@@ -151,7 +153,7 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
151
153
this . createElement = function ( options ) {
152
154
const newElement = new Element ( { ...options , scrollAxis } ) ;
153
155
newElement . setCachedAttributes ( view , scroll ) ;
154
- elements = [ ...elements , newElement ] ;
156
+ elements = elements ? [ ...elements , newElement ] : [ newElement ] ;
155
157
_updateElementPosition ( newElement ) ;
156
158
return newElement ;
157
159
} ;
@@ -171,12 +173,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
171
173
* @param {object } options
172
174
*/
173
175
this . updateElementPropsById = function ( id , props ) {
174
- elements = elements . map ( el => {
175
- if ( el . id === id ) {
176
- return el . updateProps ( props ) ;
177
- }
178
- return el ;
179
- } ) ;
176
+ if ( elements ) {
177
+ elements = elements . map ( el => {
178
+ if ( el . id === id ) {
179
+ return el . updateProps ( props ) ;
180
+ }
181
+ return el ;
182
+ } ) ;
183
+ }
180
184
181
185
this . update ( ) ;
182
186
} ;
@@ -214,7 +218,9 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
214
218
*/
215
219
this . destroy = function ( ) {
216
220
_removeListeners ( viewEl ) ;
217
- elements . forEach ( element => resetStyles ( element ) ) ;
221
+ if ( elements ) {
222
+ elements . forEach ( element => resetStyles ( element ) ) ;
223
+ }
218
224
elements = undefined ;
219
225
} ;
220
226
}
0 commit comments