1
0
mirror of https://git.topisto.net/tibo/template.git synced 2026-03-31 19:29:10 +00:00

Homogénéiser les IntersectionObserver

This commit is contained in:
Thibaud
2024-09-13 18:02:31 +02:00
parent 2030381b45
commit 51970485f2
3 changed files with 31 additions and 25 deletions

View File

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