-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
134 lines (115 loc) · 3.92 KB
/
Copy pathscript.js
File metadata and controls
134 lines (115 loc) · 3.92 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const appConfig = {
navbarOffset: 60,
scrollDuration: 'smooth',
observerThreshold: 0.1,
observerMargin: '0px 0px -100px 0px',
animationDuration: '0.4s', // Made slightly snappier
elementsToAnimate: '.project-card, .skill-category'
};
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - appConfig.navbarOffset;
window.scrollTo({
top: offsetTop,
behavior: appConfig.scrollDuration
});
}
});
});
}
function initScrollAnimations() {
const observerOptions = {
threshold: appConfig.observerThreshold,
rootMargin: appConfig.observerMargin
};
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(appConfig.elementsToAnimate).forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(15px)';
el.style.transition = `all ${appConfig.animationDuration} ease-out`;
observer.observe(el);
});
}
function initHamburgerMenu() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
});
});
}
}
function initMenuCloseOnOutside() {
document.addEventListener('click', (e) => {
const navMenu = document.querySelector('.nav-menu');
const hamburger = document.querySelector('.hamburger');
const navWrapper = document.querySelector('.nav-wrapper');
if (navMenu && navWrapper && !navWrapper.contains(e.target)) {
navMenu.classList.remove('active');
if (hamburger) {
hamburger.classList.remove('active');
}
}
});
}
function initTimelineAnimations() {
const timelineItems = document.querySelectorAll('.timeline-item');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animated');
}
});
}, { threshold: 0.2 });
timelineItems.forEach(item => observer.observe(item));
}
// Initialize hero background interactive parallax effect
function initHeroParallax() {
const hero = document.getElementById('hero');
if (!hero) return;
hero.addEventListener('mousemove', (e) => {
// Get dimensions of the hero section
const rect = hero.getBoundingClientRect();
// Calculate mouse position relative to the element
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Calculate percentage from center (-1 to 1)
// We use this multiplier to determine how intensely the grid tilts
const xPercent = (x / rect.width - 0.5) * 2;
const yPercent = (y / rect.height - 0.5) * 2;
// Pass the coordinates dynamically to CSS variables
hero.style.setProperty('--mouse-x', xPercent);
hero.style.setProperty('--mouse-y', yPercent);
});
// Smoothly snap back to center when the mouse leaves the section
hero.addEventListener('mouseleave', () => {
hero.style.setProperty('--mouse-x', 0);
hero.style.setProperty('--mouse-y', 0);
});
}
document.addEventListener('DOMContentLoaded', () => {
initSmoothScroll();
initScrollAnimations();
initHamburgerMenu();
initMenuCloseOnOutside();
initTimelineAnimations();
initHeroParallax();
});