Skip to content

check for elements #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/classes/ParallaxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
* attributes, if so set the elements parallax styles.
*/
function _updateAllElements({ updateCache } = {}) {
elements.forEach(element => {
_updateElementPosition(element);
if (updateCache) {
element.setCachedAttributes(view, scroll);
}
});
if (elements) {
elements.forEach(element => {
_updateElementPosition(element);
if (updateCache) {
element.setCachedAttributes(view, scroll);
}
});
}
// reset ticking so more animations can be called
ticking = false;
}
Expand Down Expand Up @@ -151,7 +153,7 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
this.createElement = function(options) {
const newElement = new Element({ ...options, scrollAxis });
newElement.setCachedAttributes(view, scroll);
elements = [...elements, newElement];
elements = elements ? [...elements, newElement] : [newElement];
_updateElementPosition(newElement);
return newElement;
};
Expand All @@ -171,12 +173,14 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
* @param {object} options
*/
this.updateElementPropsById = function(id, props) {
elements = elements.map(el => {
if (el.id === id) {
return el.updateProps(props);
}
return el;
});
if (elements) {
elements = elements.map(el => {
if (el.id === id) {
return el.updateProps(props);
}
return el;
});
}

this.update();
};
Expand Down Expand Up @@ -214,7 +218,9 @@ function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
*/
this.destroy = function() {
_removeListeners(viewEl);
elements.forEach(element => resetStyles(element));
if (elements) {
elements.forEach(element => resetStyles(element));
}
elements = undefined;
};
}
Expand Down