-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfix_bg.js
32 lines (28 loc) · 1.23 KB
/
fix_bg.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
// Get the section element
var section = document.getElementById('triggerSection');
var thing = document.getElementById('da_section');
// Function to check if the section is in the viewport
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
// Function to change the background color
function updateBackgroundColor() {
var body = document.body;
if (isElementInViewport(section)) {
body.style.backgroundColor = 'white'; // Section is visible
thing.style.visibility = "visible";
} else {
body.style.backgroundColor = 'black'; // Section is not visible
thing.style.visibility = "hidden";
}
}
// Attach the updateBackgroundColor function to the scroll event
window.addEventListener('scroll', updateBackgroundColor);
// Initial call to set the initial background color based on the section's visibility
updateBackgroundColor();