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:
@@ -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');
|
||||
Reference in New Issue
Block a user