-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelcome-animation.js
More file actions
27 lines (23 loc) · 822 Bytes
/
welcome-animation.js
File metadata and controls
27 lines (23 loc) · 822 Bytes
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
document.addEventListener('DOMContentLoaded', function () {
const welcomeText = document.querySelector('.Welcome');
window.addEventListener('scroll', function () {
const scrollPosition = window.scrollY;
if (scrollPosition > 100) {
document.querySelector('.navbar').classList.add('scrolled');
} else {
document.querySelector('.navbar').classList.remove('scrolled');
}
if (isElementInViewport(welcomeText)) {
welcomeText.classList.add('show');
}
});
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
});