Allow multiple widgets for the same HTMLElement

This commit is contained in:
Davide Tantillo 2024-12-11 15:41:40 +01:00
parent f9bada6d0c
commit 2b6e1ff578

View File

@ -1149,18 +1149,19 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes,
this.intersectionObserver = new IntersectionObserver((widgets) => { this.intersectionObserver = new IntersectionObserver((widgets) => {
widgets.forEach(({ isIntersecting, target, intersectionRatio }) => { widgets.forEach(({ isIntersecting, target, intersectionRatio }) => {
const widget = this.skeletonList.find(w => w.getHTMLElementReference() == target); this.skeletonList.forEach(widget => {
if (!widget) return; if (widget.getHTMLElementReference() != target) return;
// old browsers do not have isIntersecting // old browsers do not have isIntersecting
if (isIntersecting === undefined) { if (isIntersecting === undefined) {
isIntersecting = intersectionRatio > 0; isIntersecting = intersectionRatio > 0;
} }
widget.onScreen = isIntersecting; widget.onScreen = isIntersecting;
if (isIntersecting) { if (isIntersecting) {
widget.onScreenFunction(widget); widget.onScreenFunction(widget);
} }
});
}) })
}, { rootMargin: "30px 20px 30px 20px" }); }, { rootMargin: "30px 20px 30px 20px" });