forked from Dezenix/frontend-html-css-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (24 loc) · 1.04 KB
/
app.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
// listening for the scroll event
window.addEventListener('scroll', () => {
const contents = document.querySelectorAll('.child-container'); // selecting all the div with text contents
const logoImages = document.querySelectorAll('.logoImage'); // selecting all logo images
const screenPosition = window.innerHeight; // taking the scroll postion
// checking the content position on scroll event to trigger the animation of the content box
contents.forEach((content) => {
const contentPosition = content.getBoundingClientRect().top;
if (contentPosition < screenPosition) {
content.classList.add('active');
} else {
content.classList.remove('active');
}
});
// checking the logo images position on scroll event to trigger the animation of the logo images
logoImages.forEach((logoImage) => {
const logoImagePosition = logoImage.getBoundingClientRect().top;
if (logoImagePosition < screenPosition) {
logoImage.classList.add('active');
} else {
logoImage.classList.remove('active');
}
});
});