-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
70 lines (52 loc) · 1.8 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
document.addEventListener("DOMContentLoaded", function() {
const fadeInElements = document.querySelectorAll(".fade-in");
function checkVisibility() {
for (const element of fadeInElements) {
if (isElementInViewport(element)) {
element.classList.add("show");
} else {
element.classList.remove("show");
}
}
}
function isElementInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
window.addEventListener('scroll', function() {
var backToTopButton = document.getElementById('back-to-top');
if (window.scrollY > 200) {
backToTopButton.style.display = 'block';
} else {
backToTopButton.style.display = 'none';
}
});
document.getElementById('back-to-top').addEventListener('click', function(e) {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
});
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('show');
const line = entry.target.querySelector('.horizontal-line');
setTimeout(() => {
line.classList.add('animate-line');
}, 2000); // Adjust the delay as needed
} else {
entry.target.classList.remove('show');
}
});
});
const hiddenElements = document.querySelectorAll('.hidden');
hiddenElements.forEach((el) => observer.observe(el));
// Call checkVisibility on page load
checkVisibility();
// Recheck visibility on scroll
window.addEventListener('scroll', checkVisibility);
});