0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 18:12:40 +00:00

Remove loop on intersectionObserver entries

Guaranteed to only be one entry each time, since we are attaching each page to its own observers.
This commit is contained in:
Trevor Buckner
2024-12-23 22:43:37 -05:00
parent d588a92147
commit f0e047e7cc

View File

@@ -45,12 +45,10 @@ const BrewPage = (props)=>{
// Observer for tracking pages within the `.pages` div
const visibleObserver = new IntersectionObserver(
(entries)=>{
entries.forEach((entry)=>{
if(entry.isIntersecting)
props.onVisibilityChange(props.index + 1, true, false); // add page to array of visible pages.
else
props.onVisibilityChange(props.index + 1, false, false);
});
if(entries[0].isIntersecting)
props.onVisibilityChange(props.index + 1, true, false); // add page to array of visible pages.
else
props.onVisibilityChange(props.index + 1, false, false);
},
{ threshold: .3, rootMargin: '0px 0px 0px 0px' } // detect when >30% of page is within bounds.
);
@@ -58,10 +56,8 @@ const BrewPage = (props)=>{
// Observer for tracking the page at the center of the iframe.
const centerObserver = new IntersectionObserver(
(entries)=>{
entries.forEach((entry)=>{
if(entry.isIntersecting)
props.onVisibilityChange(props.index + 1, true, true); // Set this page as the center page
});
if(entries[0].isIntersecting)
props.onVisibilityChange(props.index + 1, true, true); // Set this page as the center page
},
{ threshold: 0, rootMargin: '-50% 0px -50% 0px' } // Detect when the page is at the center
);