1
0
mirror of https://git.topisto.net/tibo/template.git synced 2026-03-31 15:09:10 +00:00
Files
template/frontend/src/scripts/UI/IntersectionObserver/footer.js
2024-09-14 18:03:24 +02:00

19 lines
938 B
JavaScript

// Create a function that will handle any intersection between some elements and the viewport.
const handleFooterIntersection = function (entries) {
// Loop through all the observed elements
entries.forEach(entry => { // Check if the element is intersecting the viewport
if (entry.isIntersecting) {
msgConsole('IntersectionObserver','The footer is visible in the viewport');
if (typeof footerIsNowVisible === 'function') footerIsNowVisible(entry);
} else {
msgConsole('IntersectionObserver','The footer is invisible in the viewport');
if (typeof footerIsNowInvisible === 'function') footerIsNowInvisible(entry);
}
});
}
const section_footer = document.querySelector("#footer");
if (section_footer) {
const footerObserver = new IntersectionObserver(handleFooterIntersection);
if (footerObserver) footerObserver.observe(section_footer);
} else myLog('No footer to observe');