Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
335 lines (281 loc) · 10.6 KB
/
Copy pathscript.js
File metadata and controls
335 lines (281 loc) · 10.6 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// ====================
// Mobile Navigation Toggle
// ====================
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
// Toggle mobile menu
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking a link
navLinks.forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
// ====================
// Navbar Scroll Effect
// ====================
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// ====================
// Smooth Scroll for Navigation Links
// ====================
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 - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// ====================
// Scroll Animation Observer
// ====================
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe all elements with scroll-animate class
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll('.scroll-animate');
animateElements.forEach(el => observer.observe(el));
// Add scroll-animate class to project cards, skill cards, and contact cards
const projectCardElements = document.querySelectorAll('.project-card');
const skillCardElements = document.querySelectorAll('.skill-card');
const contactCardElements = document.querySelectorAll('.contact-card');
projectCardElements.forEach((card, index) => {
card.classList.add('scroll-animate');
card.style.transitionDelay = `${index * 0.05}s`;
observer.observe(card);
});
skillCardElements.forEach((card, index) => {
card.classList.add('scroll-animate');
card.style.transitionDelay = `${index * 0.05}s`;
observer.observe(card);
});
contactCardElements.forEach((card, index) => {
card.classList.add('scroll-animate');
card.style.transitionDelay = `${index * 0.05}s`;
observer.observe(card);
});
});
// ====================
// Active Navigation Link Highlight
// ====================
const sections = document.querySelectorAll('section[id]');
function highlightNavigation() {
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
const navLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navLinks.forEach(link => link.classList.remove('active'));
if (navLink) {
navLink.classList.add('active');
}
}
});
}
window.addEventListener('scroll', highlightNavigation);
// ====================
// Typing Effect for Hero Title (Optional Enhancement)
// ====================
function createTypingEffect(element, text, speed = 100) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// ====================
// Mouse Trail Effect (Subtle)
// ====================
let mouseTrail = [];
const maxTrailLength = 20;
document.addEventListener('mousemove', (e) => {
mouseTrail.push({ x: e.clientX, y: e.clientY, time: Date.now() });
if (mouseTrail.length > maxTrailLength) {
mouseTrail.shift();
}
});
// ====================
// Project Card Tilt Effect
// ====================
document.addEventListener('DOMContentLoaded', () => {
const projectCardElements = document.querySelectorAll('.project-card');
projectCardElements.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
// Increased tilt effect from /20 to /10 for more movement
const rotateX = (y - centerY) / 10;
const rotateY = (centerX - x) / 10;
card.style.transition = 'transform 0.1s ease-out';
card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateY(-15px) scale(1.03)`;
});
card.addEventListener('mouseleave', () => {
card.style.transition = 'transform 0.3s ease-out';
card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0) translateY(0) scale(1)';
});
});
});
// ====================
// Skill Card Hover Animation
// ====================
document.addEventListener('DOMContentLoaded', () => {
const skillCardElements = document.querySelectorAll('.skill-card');
skillCardElements.forEach(card => {
card.addEventListener('mouseenter', () => {
const icon = card.querySelector('.skill-icon');
icon.style.transform = 'scale(1.2) rotate(5deg)';
icon.style.transition = 'transform 0.3s ease';
});
card.addEventListener('mouseleave', () => {
const icon = card.querySelector('.skill-icon');
icon.style.transform = 'scale(1) rotate(0deg)';
});
});
});
// ====================
// Contact Card Hover Animation
// ====================
document.addEventListener('DOMContentLoaded', () => {
const contactCardElements = document.querySelectorAll('.contact-card');
contactCardElements.forEach(card => {
card.addEventListener('mouseenter', () => {
const icon = card.querySelector('.contact-icon');
if (icon) {
icon.style.transform = 'scale(1.2) rotate(5deg)';
icon.style.transition = 'transform 0.3s ease';
}
});
card.addEventListener('mouseleave', () => {
const icon = card.querySelector('.contact-icon');
if (icon) {
icon.style.transform = 'scale(1) rotate(0deg)';
}
});
});
});
// ====================
// Copy Email on Click
// ====================
const emailCard = document.querySelector('.contact-card[href^="mailto"]');
if (emailCard) {
emailCard.addEventListener('click', (e) => {
const email = emailCard.querySelector('p').textContent;
// Use modern Clipboard API if available
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(email).then(() => {
// Show a brief notification
const originalText = emailCard.querySelector('h4').textContent;
emailCard.querySelector('h4').textContent = 'Email Copied!';
setTimeout(() => {
emailCard.querySelector('h4').textContent = originalText;
}, 2000);
}).catch(err => {
console.log('Failed to copy email:', err);
});
} else {
// Fallback for older browsers
const tempInput = document.createElement('input');
tempInput.value = email;
document.body.appendChild(tempInput);
tempInput.select();
try {
document.execCommand('copy');
// Show a brief notification
const originalText = emailCard.querySelector('h4').textContent;
emailCard.querySelector('h4').textContent = 'Email Copied!';
setTimeout(() => {
emailCard.querySelector('h4').textContent = originalText;
}, 2000);
} catch (err) {
console.log('Failed to copy email:', err);
}
document.body.removeChild(tempInput);
}
});
}
// ====================
// Parallax Effect for Hero Background
// ====================
window.addEventListener('scroll', () => {
const hero = document.querySelector('.hero');
const scrolled = window.pageYOffset;
if (hero && scrolled < window.innerHeight) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// ====================
// Loading Animation
// ====================
window.addEventListener('load', () => {
document.body.classList.add('loaded');
// Fade in hero content
const heroContent = document.querySelector('.hero-content');
const heroImage = document.querySelector('.hero-image');
if (heroContent) {
heroContent.classList.add('fade-in-up');
}
if (heroImage) {
setTimeout(() => {
heroImage.classList.add('fade-in-up');
}, 200);
}
});
// ====================
// Dynamic Year in Footer
// ====================
const footerText = document.querySelector('.footer p');
if (footerText) {
const currentYear = new Date().getFullYear();
footerText.textContent = `© ${currentYear} rOnInRaJ. Built with passion and creativity.`;
}
// ====================
// Prevent Default for Demo Links
// ====================
document.querySelectorAll('.project-link[href="#"]').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
alert('This is a demo project link. Replace with actual project URLs!');
});
});
// ====================
// Console Message
// ====================
console.log('%c🚀 Welcome to rOnInRaJ\'s Portfolio!', 'color: #6366f1; font-size: 20px; font-weight: bold;');
console.log('%cInterested in the code? Check out the repository!', 'color: #8b5cf6; font-size: 14px;');