-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
192 lines (158 loc) · 5.9 KB
/
script.js
File metadata and controls
192 lines (158 loc) · 5.9 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Typewriter Effect for Hero Section
class TypeWriter {
constructor(element, words, typeSpeed = 100, deleteSpeed = 50, pauseTime = 2000) {
this.element = element;
this.words = words;
this.typeSpeed = typeSpeed;
this.deleteSpeed = deleteSpeed;
this.pauseTime = pauseTime;
this.currentWordIndex = 0;
this.currentText = '';
this.isDeleting = false;
this.start();
}
start() {
this.type();
}
type() {
const currentWord = this.words[this.currentWordIndex];
if (this.isDeleting) {
this.currentText = currentWord.substring(0, this.currentText.length - 1);
} else {
this.currentText = currentWord.substring(0, this.currentText.length + 1);
}
this.element.textContent = this.currentText;
let typeSpeed = this.isDeleting ? this.deleteSpeed : this.typeSpeed;
if (!this.isDeleting && this.currentText === currentWord) {
typeSpeed = this.pauseTime;
this.isDeleting = true;
} else if (this.isDeleting && this.currentText === '') {
this.isDeleting = false;
this.currentWordIndex = (this.currentWordIndex + 1) % this.words.length;
typeSpeed = 500;
}
setTimeout(() => this.type(), typeSpeed);
}
}
// Initialize typewriter effect
document.addEventListener('DOMContentLoaded', () => {
const typewriterElement = document.querySelector('.typewriter');
if (typewriterElement) {
const words = typewriterElement.getAttribute('data-words').split(',');
new TypeWriter(typewriterElement, words, 100, 55, 1700);
}
});
// scroll-based navigation highlighting
let ticking = false;
function updateActiveNav() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a');
let current = '';
sections.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
const sectionHeight = section.offsetHeight;
if (sectionTop <= 200 && sectionTop + sectionHeight > 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
ticking = false;
}
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(updateActiveNav);
ticking = true;
}
});
// Scroll Animations
const observerOptions = {
threshold: 0.15,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
// Enhanced animation for work items with optimized timing
if (entry.target.classList.contains('work-item')) {
setTimeout(() => {
entry.target.classList.add('animate');
}, 100);
} else {
entry.target.classList.add('visible');
}
}
});
}, observerOptions);
// work item animations
document.querySelectorAll('.work-item').forEach((el, index) => {
observer.observe(el);
});
document.querySelectorAll('.experience-item').forEach(el => {
el.classList.add('fade-in-up');
observer.observe(el);
});
document.querySelectorAll('.skill-category').forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
// Project Section Scrolling
function enhanceProjectScrolling() {
const workSection = document.querySelector('#work');
const workItems = document.querySelectorAll('.work-item');
// Add scroll-based parallax effect to project images
window.addEventListener('scroll', () => {
const sectionTop = workSection.offsetTop;
const sectionHeight = workSection.offsetHeight;
const scrolled = window.pageYOffset;
const rate = scrolled - sectionTop;
if (scrolled > sectionTop - window.innerHeight && scrolled < sectionTop + sectionHeight) {
workItems.forEach((item, index) => {
const image = item.querySelector('.project-screenshot');
if (image) {
const speed = 0.5 + (index * 0.1);
image.style.transform = `translateY(${rate * speed * 0.1}px)`;
}
});
}
});
}
// Skill Tag Hover Effects
document.querySelectorAll('.skill-tag').forEach(tag => {
tag.addEventListener('mouseenter', () => {
tag.style.transform = 'translateY(-2px) scale(1.05)';
});
tag.addEventListener('mouseleave', () => {
tag.style.transform = 'translateY(0) scale(1)';
});
});
// Enhanced Contact Link Interactions
document.querySelectorAll('.contact-link').forEach(link => {
// Magnetic effect
link.addEventListener('mousemove', (e) => {
const rect = link.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
link.style.transform = `translate(${x * 0.1}px, ${y * 0.1}px) scale(1.05)`;
});
link.addEventListener('mouseleave', () => {
link.style.transform = 'translate(0px, 0px) scale(1)';
});
link.addEventListener('click', (e) => {
const linkType = link.href.includes('mailto') ? 'email' :
link.href.includes('linkedin') ? 'linkedin' : 'github';
// Add ripple effect
const ripple = document.createElement('span');
ripple.classList.add('ripple');
link.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
// Mock analytics tracking
console.log(`Contact interaction: ${linkType}`);
});
});