Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
658 lines (549 loc) · 19.5 KB
/
Copy pathscript.js
File metadata and controls
658 lines (549 loc) · 19.5 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
document.addEventListener("DOMContentLoaded", () => {
// Custom Cursor
const customCursor = document.getElementById("customCursor")
const cursorFollower = document.getElementById("cursorFollower")
if (customCursor && cursorFollower && window.innerWidth > 768) {
let mouseX = 0
let mouseY = 0
let followerX = 0
let followerY = 0
document.addEventListener("mousemove", (e) => {
mouseX = e.clientX
mouseY = e.clientY
customCursor.style.left = mouseX + "px"
customCursor.style.top = mouseY + "px"
})
// Smooth follower animation
function animateFollower() {
const speed = 0.2
followerX += (mouseX - followerX) * speed
followerY += (mouseY - followerY) * speed
cursorFollower.style.left = followerX + "px"
cursorFollower.style.top = followerY + "px"
requestAnimationFrame(animateFollower)
}
animateFollower()
// Cursor hover effects
const hoverElements = document.querySelectorAll("a, button, .btn, .project-card, .skill-bar")
hoverElements.forEach((element) => {
element.addEventListener("mouseenter", () => {
customCursor.classList.add("hover")
cursorFollower.classList.add("hover")
})
element.addEventListener("mouseleave", () => {
customCursor.classList.remove("hover")
cursorFollower.classList.remove("hover")
})
})
}
// Scroll Progress Bar
const scrollProgressBar = document.getElementById("scrollProgressBar")
function updateScrollProgress() {
const scrollTop = window.pageYOffset
const docHeight = document.documentElement.scrollHeight - window.innerHeight
const scrollPercent = (scrollTop / docHeight) * 100
scrollProgressBar.style.width = `${scrollPercent}%`
}
window.addEventListener("scroll", updateScrollProgress)
// 3D Scroll Effects for Images
const scroll3DImages = document.querySelectorAll("[data-scroll-3d]")
function update3DScrollEffects() {
scroll3DImages.forEach((element) => {
const rect = element.getBoundingClientRect()
const scrolled = window.pageYOffset
const rate = scrolled * -0.5
const yPos = -(rate / 10)
const rotateY = (rect.top - window.innerHeight / 2) * 0.02
const rotateX = (rect.left - window.innerWidth / 2) * 0.01
const image = element.querySelector(".scroll-3d-image")
if (image) {
image.style.transform = `translateY(${yPos}px) rotateY(${rotateY}deg) rotateX(${rotateX}deg) translateZ(20px)`
}
})
}
window.addEventListener("scroll", update3DScrollEffects)
// Navigation Toggle
const navbarToggler = document.querySelector(".navbar-toggler")
const navbarCollapse = document.querySelector(".navbar-collapse")
if (navbarToggler && navbarCollapse) {
// Toggle menu when toggler is clicked
navbarToggler.addEventListener("click", () => {
navbarCollapse.classList.toggle("show")
navbarToggler.classList.toggle("active")
navbarToggler.setAttribute(
"aria-expanded",
navbarToggler.getAttribute("aria-expanded") === "false" ? "true" : "false",
)
})
// Close menu when a navigation link is clicked
document.querySelectorAll(".nav-links a").forEach((link) => {
link.addEventListener("click", () => {
navbarCollapse.classList.remove("show")
navbarToggler.classList.remove("active")
navbarToggler.setAttribute("aria-expanded", "false")
})
})
// Close menu when clicking outside
document.addEventListener("click", (e) => {
if (
!navbarToggler.contains(e.target) &&
!navbarCollapse.contains(e.target) &&
navbarCollapse.classList.contains("show")
) {
navbarCollapse.classList.remove("show")
navbarToggler.classList.remove("active")
navbarToggler.setAttribute("aria-expanded", "false")
}
})
}
// Header scroll effect
const header = document.querySelector("header")
if (header) {
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
header.classList.add("scrolled")
} else {
header.classList.remove("scrolled")
}
})
}
// Back to Top Button
const backToTopButton = document.querySelector(".back-to-top")
if (backToTopButton) {
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
backToTopButton.classList.add("active")
} else {
backToTopButton.classList.remove("active")
}
})
backToTopButton.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth",
})
})
}
// Follow Along Links Navigation System
class FollowAlongNavigation {
constructor() {
this.navLinks = document.querySelectorAll(".nav-link")
this.highlight = document.getElementById("navHighlight")
this.sections = document.querySelectorAll("section")
this.currentSection = "home"
this.isScrolling = false
this.init()
}
init() {
this.setupEventListeners()
this.updateHighlight()
this.observeSections()
}
setupEventListeners() {
// Navigation link clicks
this.navLinks.forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault()
const targetId = link.getAttribute("href").substring(1)
this.scrollToSection(targetId)
this.setActiveLink(link)
})
// Hover effects
link.addEventListener("mouseenter", () => {
if (!this.isScrolling && window.innerWidth > 768) {
this.updateHighlight(link)
}
})
})
// Return highlight to active link when not hovering
const navLinksContainer = document.querySelector(".nav-links")
if (navLinksContainer) {
navLinksContainer.addEventListener("mouseleave", () => {
if (!this.isScrolling && window.innerWidth > 768) {
const activeLink = document.querySelector(".nav-link.active")
this.updateHighlight(activeLink)
}
})
}
// Scroll events
window.addEventListener("scroll", () => {
this.updateActiveSection()
})
// Resize events
window.addEventListener("resize", () => {
if (window.innerWidth > 768) {
this.updateHighlight()
}
})
}
updateHighlight(targetLink = null) {
if (window.innerWidth <= 768) return // Don't show highlight on mobile
const activeLink = targetLink || document.querySelector(".nav-link.active")
if (!activeLink || !this.highlight) return
const linkRect = activeLink.getBoundingClientRect()
const navRect = document.querySelector(".nav-links").getBoundingClientRect()
const left = linkRect.left - navRect.left - 8
const width = linkRect.width
const height = linkRect.height
this.highlight.style.left = `${left}px`
this.highlight.style.width = `${width}px`
this.highlight.style.height = `${height}px`
}
setActiveLink(clickedLink) {
this.navLinks.forEach((link) => link.classList.remove("active"))
clickedLink.classList.add("active")
this.updateHighlight(clickedLink)
}
scrollToSection(sectionId) {
const section = document.getElementById(sectionId)
if (section) {
this.isScrolling = true
section.scrollIntoView({
behavior: "smooth",
block: "start",
})
// Reset scrolling flag after animation
setTimeout(() => {
this.isScrolling = false
}, 1000)
}
}
updateActiveSection() {
if (this.isScrolling) return
const scrollPosition = window.scrollY + 150
this.sections.forEach((section) => {
const sectionTop = section.offsetTop
const sectionHeight = section.offsetHeight
const sectionId = section.getAttribute("id")
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
if (this.currentSection !== sectionId) {
this.currentSection = sectionId
const correspondingLink = document.querySelector(`a[href="#${sectionId}"]`)
if (correspondingLink) {
this.setActiveLink(correspondingLink)
}
}
}
})
}
observeSections() {
const observerOptions = {
threshold: 0.3,
rootMargin: "-50px 0px -50px 0px",
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
const sectionContent = entry.target.querySelector(".section-content")
if (entry.isIntersecting && sectionContent) {
sectionContent.classList.add("visible")
}
})
}, observerOptions)
this.sections.forEach((section) => {
observer.observe(section)
})
}
}
// Initialize Follow Along Navigation
new FollowAlongNavigation()
// Parallax Effects for Floating Shapes
const floatingShapes = document.querySelectorAll(".shape")
function updateParallaxShapes() {
const scrolled = window.pageYOffset
floatingShapes.forEach((shape, index) => {
const speed = 0.5 + index * 0.1
const yPos = -(scrolled * speed)
const rotation = scrolled * 0.05 * (index + 1)
shape.style.transform = `translateY(${yPos}px) rotate(${rotation}deg)`
})
}
window.addEventListener("scroll", updateParallaxShapes)
// Scroll Animation
const animateElements = document.querySelectorAll(
".animate-on-scroll, .section-title, .about-image, .about-text, .skill-category, .project-card, .resume-download, .resume-section, .contact-info, .contact-form",
)
function checkScroll() {
const triggerBottom = window.innerHeight * 0.85
animateElements.forEach((element) => {
const elementTop = element.getBoundingClientRect().top
if (elementTop < triggerBottom) {
element.classList.add("fade-in")
}
})
}
// Initial check
checkScroll()
// Check on scroll
window.addEventListener("scroll", checkScroll)
// Skill Progress Animation
const progressBars = document.querySelectorAll(".progress")
function animateProgressBars() {
progressBars.forEach((bar) => {
const percent = bar.getAttribute("data-percent")
bar.style.width = percent
})
}
const skillsSection = document.querySelector(".skills")
function checkSkillsVisibility() {
if (skillsSection) {
const skillsPosition = skillsSection.getBoundingClientRect().top
const screenPosition = window.innerHeight * 0.85
if (skillsPosition < screenPosition) {
animateProgressBars()
setTimeout(() => {
animateSkillCounters()
}, 500) // Start counter animation after progress bars
window.removeEventListener("scroll", checkSkillsVisibility)
}
}
}
window.addEventListener("scroll", checkSkillsVisibility)
checkSkillsVisibility()
// Animated Skill Counters
function animateSkillCounters() {
const skillPercents = document.querySelectorAll(".skill-percent[data-target]")
skillPercents.forEach((percent) => {
const target = Number.parseInt(percent.getAttribute("data-target"))
let current = 0
const increment = target / 50 // Animation duration control
const updateCounter = () => {
if (current < target) {
current += increment
percent.textContent = Math.ceil(current) + "%"
requestAnimationFrame(updateCounter)
} else {
percent.textContent = target + "%"
}
}
updateCounter()
})
}
// Form Submission with validation
const contactForm = document.getElementById("contactForm")
if (contactForm) {
const attachRealtimeValidation = () => {
contactForm.querySelectorAll("input, textarea").forEach((input) => {
input.addEventListener("input", function () {
if (this.value.trim()) {
this.style.borderColor = "var(--primary-color)"
this.style.backgroundColor = "white"
}
})
})
}
contactForm.addEventListener("submit", async (e) => {
e.preventDefault()
// Basic validation
let isValid = true
const inputs = contactForm.querySelectorAll("input, textarea")
inputs.forEach((input) => {
if (!input.value.trim()) {
isValid = false
input.style.borderColor = "var(--danger-color)"
input.style.backgroundColor = "rgba(239, 68, 68, 0.05)"
// Add shake animation
input.classList.add("shake")
setTimeout(() => {
input.classList.remove("shake")
}, 500)
} else {
input.style.borderColor = "var(--success-color)"
input.style.backgroundColor = "rgba(16, 185, 129, 0.05)"
}
})
if (isValid) {
const name = document.getElementById("name").value.trim()
const email = document.getElementById("email").value.trim()
const subject = document.getElementById("subject").value.trim()
const message = document.getElementById("message").value.trim()
const submitButton = contactForm.querySelector('button[type="submit"]')
const originalButtonText = submitButton ? submitButton.textContent : ""
if (submitButton) {
submitButton.disabled = true
submitButton.textContent = "Sending..."
}
const apiBaseUrl = String(window.CONTACT_API_BASE_URL || "").replace(/\/$/, "")
const requestUrl = apiBaseUrl ? `${apiBaseUrl}/api/contact` : "/api/contact"
try {
const response = await fetch(requestUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ name, email, subject, message }),
})
if (!response.ok) {
throw new Error("Request failed")
}
// Success message with animation
const formContent = contactForm.innerHTML
contactForm.innerHTML = `
<div class="success-message" style="text-align: center; padding: 30px;">
<div style="font-size: 3rem; color: var(--success-color); margin-bottom: 20px;">
<i class="fas fa-check-circle"></i>
</div>
<h3 style="margin-bottom: 15px; color: var(--success-color);">Message Sent Successfully!</h3>
<p style="margin-bottom: 20px; color: var(--gray-color);">Thank you for your message! I will get back to you soon.</p>
<button type="button" class="btn primary-btn" id="resetForm">Send Another Message</button>
</div>
`
// Reset form button
document.getElementById("resetForm").addEventListener("click", () => {
contactForm.innerHTML = formContent
attachRealtimeValidation()
})
} catch (error) {
alert("Failed to send message. Please try again later.")
if (submitButton) {
submitButton.disabled = false
submitButton.textContent = originalButtonText
}
}
}
})
// Real-time validation
attachRealtimeValidation()
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault()
const targetId = this.getAttribute("href")
if (targetId === "#") return
const targetElement = document.querySelector(targetId)
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: "smooth",
})
}
})
})
// Parallax effect for hero section
const hero = document.querySelector(".hero")
if (hero) {
window.addEventListener("scroll", () => {
const scrollPosition = window.scrollY
if (scrollPosition < 600) {
hero.style.backgroundPosition = `center ${scrollPosition * 0.4}px`
}
})
}
// Add typing effect to hero section
const heroTitle = document.querySelector(".hero-content h2")
if (heroTitle) {
const originalText = heroTitle.textContent
heroTitle.textContent = ""
let i = 0
const typeWriter = () => {
if (i < originalText.length) {
heroTitle.textContent += originalText.charAt(i)
i++
setTimeout(typeWriter, 100)
} else {
// Add blinking cursor at the end
heroTitle.innerHTML = heroTitle.textContent + '<span class="cursor">|</span>'
// Blink the cursor
setInterval(() => {
const cursor = document.querySelector(".cursor")
if (cursor) {
cursor.style.opacity = cursor.style.opacity === "0" ? "1" : "0"
}
}, 500)
}
}
// Start typing effect after a delay
setTimeout(typeWriter, 1000)
}
// Enhanced Project Card Interactions
const projectCards = document.querySelectorAll(".project-card")
projectCards.forEach((card) => {
const overlay = card.querySelector(".project-overlay")
const links = card.querySelector(".project-links")
card.addEventListener("mouseenter", function () {
// Ensure overlay is visible
if (overlay) {
overlay.style.opacity = "1"
overlay.style.visibility = "visible"
}
if (links) {
links.style.transform = "translateY(0)"
}
// Dim other cards
projectCards.forEach((c) => {
if (c !== this) {
c.style.opacity = "0.7"
c.style.transform = "scale(0.95)"
}
})
})
card.addEventListener("mouseleave", () => {
// Reset overlay
if (overlay) {
overlay.style.opacity = "0"
overlay.style.visibility = "hidden"
}
if (links) {
links.style.transform = "translateY(20px)"
}
// Reset all cards
projectCards.forEach((c) => {
c.style.opacity = "1"
c.style.transform = "translateY(0)"
})
})
// Ensure links are clickable
const projectLinks = card.querySelectorAll(".project-links a")
projectLinks.forEach((link) => {
link.addEventListener("click", (e) => {
e.stopPropagation()
// Link will work normally
})
})
})
// Enhanced 3D Background Effects
const bgElements = document.querySelectorAll(".bg-element")
function update3DBackground() {
const scrolled = window.pageYOffset
const mouseX = window.innerWidth / 2
const mouseY = window.innerHeight / 2
bgElements.forEach((element, index) => {
const speed = 0.3 + index * 0.1
const rotationSpeed = 0.02 + index * 0.01
const yPos = -(scrolled * speed)
const rotationY = scrolled * rotationSpeed
const rotationX = (mouseY - window.innerHeight / 2) * 0.01
element.style.transform = `translateY(${yPos}px) rotateY(${rotationY}deg) rotateX(${rotationX}deg)`
})
}
window.addEventListener("scroll", update3DBackground)
window.addEventListener("mousemove", (e) => {
if (window.innerWidth > 768) {
update3DBackground()
}
})
// Add CSS for cursor animation
const style = document.createElement("style")
style.textContent = `
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.shake {
animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
.cursor {
font-weight: 100;
animation: blink 1s infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
.success-message {
animation: fadeInUp 0.5s ease forwards;
}
`
document.head.appendChild(style)
})