-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
113 lines (97 loc) · 3.34 KB
/
Copy pathscript.js
File metadata and controls
113 lines (97 loc) · 3.34 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// ===== MOBILE NAVIGATION =====
const navToggle = document.getElementById('navToggle');
const navMenu = document.getElementById('navMenu');
const navLinks = document.querySelectorAll('.nav-link');
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a link & smooth scroll
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
// Close menu
navToggle.classList.remove('active');
navMenu.classList.remove('active');
// Smooth scroll
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 70;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// ===== NAVBAR STYLING ON SCROLL =====
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.background = 'rgba(15, 23, 42, 0.98)';
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.3)';
} else {
navbar.style.background = 'rgba(15, 23, 42, 0.95)';
navbar.style.boxShadow = 'none';
}
// Active navigation link on scroll
let current = '';
const sections = document.querySelectorAll('section');
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 100) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
});
// ===== INTERSECTION OBSERVER FOR ANIMATIONS =====
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
document.querySelectorAll('.project-card, .skill-category, .about-text').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
observer.observe(el);
});
// ===== HERO PARALLAX EFFECT =====
const heroContent = document.querySelector('.hero-content');
window.addEventListener('scroll', () => {
if (heroContent) {
const scrolled = window.pageYOffset;
heroContent.style.transform = `translateY(${scrolled * 0.3}px)`;
heroContent.style.opacity = 1 - (scrolled * 0.002);
}
});
// ===== HERO TYPING EFFECT (OPTIONAL) =====
const subtitle = document.querySelector('.hero-subtitle');
if (subtitle) {
const text = subtitle.textContent;
subtitle.textContent = '';
let i = 0;
const typeWriter = () => {
if (i < text.length) {
subtitle.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
}
};
setTimeout(typeWriter, 1000);
}