mirror of
https://git.topisto.net/tibo/template.git
synced 2026-03-31 23:49:11 +00:00
initialisation with SMETI code
This commit is contained in:
19
frontend/src/scripts/UI/IntersectionObserver/footer.js
Normal file
19
frontend/src/scripts/UI/IntersectionObserver/footer.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
if (entry.isIntersecting) {
|
||||
console.log("The footer is visible in the viewport");
|
||||
if (typeof footerIsNowVisible === 'function') footerIsNowVisible(entry);
|
||||
} else {
|
||||
console.log("The footer is invisible in the viewport");
|
||||
if (typeof footerIsNowInvisible === 'function') footerIsNowInvisible(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
const footer = document.querySelector("#footer");
|
||||
if (footer) {
|
||||
const footerObserver = new IntersectionObserver(handleFooterIntersection);
|
||||
footerObserver.observe(footer);
|
||||
}
|
||||
12
frontend/src/scripts/UI/IntersectionObserver/header.js
Normal file
12
frontend/src/scripts/UI/IntersectionObserver/header.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const headerObserver = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
if (typeof headerIsVisible === 'function') headerIsVisible(entry.isIntersecting);
|
||||
});
|
||||
});
|
||||
|
||||
const header = document.querySelector("header");
|
||||
if (header) headerObserver.observe(header);
|
||||
else myLog('No header to observe');
|
||||
|
||||
|
||||
|
||||
17
frontend/src/scripts/UI/IntersectionObserver/synthesis.js
Normal file
17
frontend/src/scripts/UI/IntersectionObserver/synthesis.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const synthesisTopObserver = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
// Check if the element is intersecting the viewport
|
||||
if (entry.isIntersecting) {
|
||||
myLog("The synthesis is visible in the viewport");
|
||||
if (typeof synthesisTopIsNowVisible === 'function') synthesisTopIsNowVisible(entry);
|
||||
} else {
|
||||
myLog("The synthesis is invisible in the viewport");
|
||||
if (typeof synthesisTopIsNowInvisible === 'function') synthesisTopIsNowInvisible(entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const synthesis_top = document.querySelector("#synthesis_top");
|
||||
if (synthesis_top) synthesisTopObserver.observe(synthesis_top);
|
||||
else myLog('No #synthesis_top to obseve');
|
||||
|
||||
Reference in New Issue
Block a user