@@ -91,12 +91,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
9191 * attributes, if so set the elements parallax styles.
9292 */
9393 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+ }
100102 // reset ticking so more animations can be called
101103 ticking = false ;
102104 }
@@ -151,7 +153,7 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
151153 this . createElement = function ( options ) {
152154 const newElement = new Element ( { ...options , scrollAxis } ) ;
153155 newElement . setCachedAttributes ( view , scroll ) ;
154- elements = [ ...elements , newElement ] ;
156+ elements = elements ? [ ...elements , newElement ] : [ newElement ] ;
155157 _updateElementPosition ( newElement ) ;
156158 return newElement ;
157159 } ;
@@ -171,12 +173,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
171173 * @param {object } options
172174 */
173175 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+ }
180184
181185 this . update ( ) ;
182186 } ;
@@ -214,7 +218,9 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
214218 */
215219 this . destroy = function ( ) {
216220 _removeListeners ( viewEl ) ;
217- elements . forEach ( element => resetStyles ( element ) ) ;
221+ if ( elements ) {
222+ elements . forEach ( element => resetStyles ( element ) ) ;
223+ }
218224 elements = undefined ;
219225 } ;
220226}
0 commit comments