-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfooter.js
48 lines (41 loc) · 1.42 KB
/
footer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
let footerTimeout;
const footer = document.querySelector('.footerDynamic'); // Select by class
if (footer) {
function showFooter(temporary = true) {
footer.style.opacity = '1';
footer.style.pointerEvents = 'auto'; // Enable interaction
// If it's a temporary show, hide after 1.5 seconds
if (temporary) {
clearTimeout(footerTimeout);
footerTimeout = setTimeout(() => {
if (!isAtBottom()) {
hideFooter();
}
}, 1500);
}
}
function hideFooter() {
footer.style.opacity = '0';
footer.style.pointerEvents = 'none'; // Disable interaction when hidden
}
function isAtBottom() {
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
}
function contentAllowsScroll() {
return document.body.offsetHeight > window.innerHeight;
}
// Show footer when scrolling down
window.addEventListener('scroll', () => {
if (isAtBottom()) {
showFooter(false); // Keep footer visible when at bottom
} else {
showFooter(true); // Temporary show when scrolling
}
});
// Check if scrolling is possible on page load
if (!contentAllowsScroll()) {
showFooter(false); // Show footer permanently if no scrolling
} else {
hideFooter(); // Hide initially if scrolling is possible
}
}