Skip to content

Commit

Permalink
only create intersection observer for section
Browse files Browse the repository at this point in the history
  • Loading branch information
metamoni committed Mar 6, 2023
1 parent 3bb7505 commit 5674f85
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions assets/animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function onIntersection(elements, observer) {
})
}

function initializeScrollAnimationTrigger() {
function initializeScrollAnimationTrigger(rootEl = document) {
const animationTriggerElements = Array.from(
document.getElementsByClassName(SCROLL_ANIMATION_TRIGGER_CLASSNAME)
rootEl.getElementsByClassName(SCROLL_ANIMATION_TRIGGER_CLASSNAME)
);
if (animationTriggerElements.length === 0) return;

Expand All @@ -26,4 +26,4 @@ function initializeScrollAnimationTrigger() {

window.addEventListener('DOMContentLoaded', () => initializeScrollAnimationTrigger());

document.addEventListener('shopify:section:load', () => initializeScrollAnimationTrigger());
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event.target));

0 comments on commit 5674f85

Please sign in to comment.