-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
72 lines (61 loc) · 1.72 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
61
62
63
64
65
66
67
68
69
70
71
72
document.addEventListener('DOMContentLoaded', (event) => {
// Initialize Lenis for smooth scrolling
const lenis = new Lenis()
function raf(time) {
lenis.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
// Typewriter effect for the hero section
const typewriterText = document.getElementById('typewriter-text');
const text = typewriterText.textContent;
typewriterText.textContent = '';
let i = 0;
const typeWriter = () => {
if (i < text.length) {
typewriterText.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
} else {
setTimeout(() => {
typewriterText.textContent = '';
i = 0;
typeWriter();
}, 3000);
}
};
typeWriter();
// Navbar visibility
const navbar = document.getElementById('navbar');
const mainLogo = document.querySelector('header .logo-container');
const toTopBtn = document.getElementById('to-top-btn');
window.addEventListener('scroll', () => {
const mainLogoRect = mainLogo.getBoundingClientRect();
if (mainLogoRect.bottom <= 0) {
navbar.classList.remove('hidden');
} else {
navbar.classList.add('hidden');
}
});
toTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Project cards animation
const projectCards = document.querySelectorAll('.project-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1
});
projectCards.forEach(card => {
observer.observe(card);
});
});