-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyscript.js
More file actions
executable file
·866 lines (769 loc) · 29.3 KB
/
Copy pathmyscript.js
File metadata and controls
executable file
·866 lines (769 loc) · 29.3 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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
// }
// // END
// show contact div
var contactinfo =
'<section class="" style="padding-bottom:0vh;padding-top:0vh"> \
<div class="flex flex-col sm:flex-row justify-start items-start gap-8"> \
<ul class="list-none flex flex-col"> \
<li><strong>Ariel Churi</strong></li> \
<li><a href="mailto:ac@sparklelabs.com" class="link-slide">ac@sparklelabs.com</a></li> \
<li><a href="tel:646-450-4576" class="link-slide">(646) 450-4576</a></li> \
<li><a href="https://calendly.com/arielchuri/30min" target=_blank class="link-slide">Create a 30min. meeting.</a></li> \
<li><a href="https://arielchuri.sparklelabs.com" target=_blank class="link-slide">arielchuri.sparklelabs.com</a></li> \
<li><a href="https://linkedin.com/in/arielchuri/" target=_blank class="link-slide">linkedin.com/in/arielchuri</a></li> \
</ul> \
<ul class="list-none flex flex-col" > \
<li><a href="https://goo.gl/maps/oHnA1aaUuyH7s5W99" target=_blank class="link-slide">Montclair, NJ</a></li> \
<li>he/him or they/them</li> \
<li><a href="https://arielchuri.sparklelabs.com/resume/pronounce.mp3" target=_blank class="link-slide">ari-EL choo-REE</a> <a href="https://arielchuri.sparklelabs.com/resume/pronounce.mp3" target=_blank class="link-slide"><img style="display:inline-block;height:18px;width:18px;vertical-align:middle" src="resume/audio-document.svg"/></a></li> \
<li><a href="https://arielchuri.sparklelabs.com/resume/arielchuri_resume.pdf" target=_blank class="link-slide">arielchuri_resume.pdf</a> <a href="https://arielchuri.sparklelabs.com/resume/arielchuri_resume.pdf" target=_blank class="link-slide"><img style="display:inline-block;height:18px;width:18px;vertical-align:middle" src="resume/pdf-file.svg"></a></li> \
<li><a href="https://github.com/arielchuri/" target=_blank class="link-slide">github.com/arielchuri</a></li> \
<li><a href="https://wireless2.fcc.gov/UlsApp/UlsSearch/license.jsp?licKey=3835821" target=_blank class="link-slide">KD2LPU</a></li> \
</ul> \
</div> \
</section> ';
// Simple section tracking for return button
function getCurrentSection() {
const sections = [
"sparkle-labs",
"bridgestone",
"sothebys",
"calvin-klein",
"unilever",
"ibm-holobot",
"moma-killscreen",
"more-work",
];
const scrollPosition = window.scrollY + window.innerHeight / 2;
for (let i = sections.length - 1; i >= 0; i--) {
const section = document.getElementById(sections[i]);
if (section && section.offsetTop <= scrollPosition) {
return sections[i];
}
}
return ""; // No anchor if at top
}
function saveCurrentSection() {
const currentSection = getCurrentSection();
sessionStorage.setItem("indexSection", currentSection);
}
function updateReturnButton() {
const returnButton = document.getElementById("returnbutton");
if (returnButton) {
// Get saved section from sessionStorage
const savedSection = sessionStorage.getItem("indexSection") || "";
const anchor = savedSection ? `#${savedSection}` : "";
returnButton.innerHTML = `<a href="index.html${anchor}" class="btn-outline btn-extrasmall inline-block" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">↩ Return</span></a>`;
}
}
function toggleContactBar(forceHide = false) {
const div = document.getElementById("contactDiv");
if (!div) return;
const isVisible = div.classList.contains("show");
if (isVisible || forceHide) {
div.classList.remove("show");
div.classList.add("hide");
setTimeout(() => {
if (div.classList.contains("hide")) {
div.style.display = "none";
}
}, 1000);
} else {
// Reset state before showing
div.style.display = "block";
div.classList.remove("show");
div.classList.add("hide"); // Start in hidden position
void div.offsetHeight; // Force reflow
div.classList.remove("hide");
div.classList.add("show"); // Then animate to visible
}
}
// Animation initialization function
function initializePageAnimations() {
// Create nav buttons
const returnButton = document.getElementById("returnbutton");
const resumeButton = document.getElementById("resumebutton");
const contactButton = document.getElementById("contactbutton");
const projectsButton = document.getElementById("projectsbutton");
const physicalButton = document.getElementById("physicalbutton");
const mobileButton = document.getElementById("mobilebutton");
if (returnButton) {
updateReturnButton();
// Update return button as user scrolls (only on index page)
if (
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html")
) {
window.addEventListener("scroll", function () {
saveCurrentSection(); // Save current section as user scrolls
updateReturnButton();
});
}
}
if (resumeButton) {
resumeButton.innerHTML =
'<a href="resume.html" class="btn-outline btn-extrasmall inline-block" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">résumé</span></a>';
}
if (projectsButton) {
const isCurrentlyOnIndex =
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html");
const href = isCurrentlyOnIndex
? "#sparkle-labs"
: "index.html#sparkle-labs";
projectsButton.innerHTML = `<a href="${href}" class="btn-outline btn-extrasmall inline-block" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">projects</span></a>`;
}
if (mobileButton) {
mobileButton.innerHTML =
'<a href="g_mobile.html" class="btn-outline btn-extrasmall inline-block" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">mobile</span></a>';
}
if (physicalButton) {
physicalButton.innerHTML =
'<a href="g_physical.html" class="btn-outline btn-extrasmall inline-block" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">physical</span></a>';
}
user = "ac";
site =
"sparklelabs.com";
if (contactButton) {
contactButton.innerHTML =
'<a class="btn-outline btn-extrasmall inline-block" onclick="toggleContactBar()" style="position: relative; overflow: hidden;"><span class="wipe-bg"></span><span class="btn-text">contact</span></a>';
}
const contactDiv = document.getElementById("contactDiv");
if (contactDiv) {
// Move contactDiv to document body if it's nested inside other containers
if (contactDiv.parentElement && !contactDiv.parentElement.matches("body")) {
document.body.insertBefore(contactDiv, document.body.firstChild);
}
contactDiv.innerHTML = `<div class="max-w-[2000px] mx-auto px-4 sm:px-6 md:px-8 lg:px-12 xl:px-16 2xl:px-20 pt-14 pb-2 flex items-start">${contactinfo}</div>`;
// Ensure consistent initial state across all pages
contactDiv.style.display = "none";
contactDiv.classList.remove("show", "hide");
contactDiv.classList.add("hide");
}
const footer = document.getElementById("footer");
if (footer) {
footer.innerHTML =
'<hr class="zig"> <hr class="zag"> <div class="mx-auto max-w-[2000px] px-4 sm:px-6 md:px-8 lg:px-12 xl:px-16 2xl:px-20"><div class="twelve columns small">' +
contactinfo +
// '<h6>Colophon</h6>' +
'<p class="small" style="padding:0px;">🄯 Ariel Churi in 2026.</br>' +
"This document was written in vanilla HTML, javascript, and CSS. " +
'The CSS started from <a href="http:www.getskeleton.com" target="_blank" class="link-slide">Skeleton</a>. The typeface is <a href="https:rsms.me/inter/" target="_blank" class="link-slide">Inter</a>. </p></div></section>';
}
// Button animations (wipe + ripple)
const buttons = document.querySelectorAll(
".btn-primary, .btn-secondary, .btn-outline",
);
buttons.forEach((btn) => {
// Wipe animation
const bg = btn.querySelector(".wipe-bg");
if (bg) {
btn.addEventListener("mouseenter", () => {
anime({
targets: bg,
width: ["0%", "100%"],
duration: 500,
easing: "easeInOutCubic",
});
});
btn.addEventListener("mouseleave", () => {
anime({
targets: bg,
width: ["100%", "0%"],
duration: 500,
easing: "easeInOutCubic",
});
});
}
// Ripple animation
btn.addEventListener("click", function (e) {
// Remove any existing ripple
const oldRipple = btn.querySelector(".ripple");
if (oldRipple) oldRipple.remove();
// Get click position relative to button
const rect = btn.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Create ripple element
const ripple = document.createElement("span");
ripple.className = "ripple";
ripple.style.left = x + "px";
ripple.style.top = y + "px";
btn.appendChild(ripple);
// Animate ripple
anime({
targets: ripple,
scale: [0, 4],
opacity: [1, 0],
duration: 600,
easing: "easeOutCubic",
complete: () => ripple.remove(),
});
});
});
// Page slide-in animation for index page
const isIndexPage =
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html");
const isResumePage = window.location.pathname.endsWith("resume.html");
// Nav animation for all pages
const nav = document.querySelector("nav");
if (nav) {
// Reset initial state for nav (important for browser back/forward)
nav.style.opacity = "0";
nav.style.transform = "translateY(-20px)";
// Fade in nav from top
anime({
targets: nav,
opacity: [1],
translateY: [0],
duration: 600,
easing: "easeInOutCubic",
delay: 300,
});
}
if (isIndexPage) {
// Find the main content container
const mainContent = document.getElementById("mainContent");
if (mainContent) {
// Reset initial state (important for browser back/forward)
mainContent.classList.remove("preload");
mainContent.style.opacity = "0";
mainContent.style.transform = "translateX(-100%)";
anime({
targets: mainContent,
translateX: ["-100%", "0px"],
opacity: [0, 1],
duration: 800,
easing: "easeInOutCubic",
delay: 100,
complete: function () {
// Ensure final position is exactly 0
mainContent.style.transform = "translateX(0px)";
},
});
// Add scroll-based animation for "Ariel Churi" title
const arielTitle = document.getElementById("ariel-churi-title");
if (arielTitle) {
// Calculate initial position based on current scroll position
const initialScrollTop = window.scrollY;
const maxScroll = window.innerHeight;
const initialScrollProgress = Math.min(initialScrollTop / maxScroll, 1);
const initialTranslateX = initialScrollProgress * -100;
// Set initial position before fading in
anime.set(arielTitle, {
translateX: `${initialTranslateX}vw`,
translateY: "-50%",
});
// Fade in title
anime({
targets: arielTitle,
opacity: [0, 1],
duration: 800,
easing: "easeInOutCubic",
delay: 300,
});
let ticking = false;
function updateTitlePosition() {
const scrollTop = window.scrollY;
const maxScroll = window.innerHeight; // First viewport height
const scrollProgress = Math.min(scrollTop / maxScroll, 1);
// Move left as we scroll down (0 to -100vw)
const translateX = scrollProgress * -100;
// Use anime.js set to maintain exact positioning
anime.set(arielTitle, {
translateX: `${translateX}vw`,
translateY: "-50%",
});
ticking = false;
}
function onScroll() {
if (!ticking) {
requestAnimationFrame(updateTitlePosition);
ticking = true;
}
}
window.addEventListener("scroll", onScroll);
}
// Find background animation element
const backgroundAnimation = document.getElementById(
"background-animation",
);
// Reset initial opacity for background (important for browser back/forward)
if (backgroundAnimation) {
backgroundAnimation.style.opacity = "0";
}
// Fade in background
if (backgroundAnimation) {
anime({
targets: backgroundAnimation,
opacity: [1],
duration: 1000,
easing: "easeInOutCubic",
delay: 200,
});
}
// Handle internal link clicks for slide-out
document.addEventListener("click", function (e) {
const link = e.target.closest("a");
if (
link &&
link.href &&
link.href.includes(window.location.origin) &&
(!link.href.includes("#") || link.href.includes("index.html")) &&
!link.getAttribute("href").startsWith("#")
) {
e.preventDefault();
// Save current section before navigating
saveCurrentSection();
// Determine slide direction based on destination
const isGoingToIndex =
link.href.includes("index.html") || link.href.endsWith("/");
const slideOutDirection = isGoingToIndex ? "right" : "left";
// Fade out nav and title first
if (nav) {
anime({
targets: nav,
opacity: [0],
translateY: [-20],
duration: 300,
easing: "easeInOutCubic",
});
}
// Fade out title on page transition
const arielTitleTransition =
document.getElementById("ariel-churi-title");
if (arielTitleTransition) {
anime({
targets: arielTitleTransition,
opacity: [0],
duration: 300,
easing: "easeInOutCubic",
});
}
// Fade out background
if (backgroundAnimation) {
anime({
targets: backgroundAnimation,
opacity: [0],
duration: 900,
easing: "easeInOutCubic",
});
}
// Slide out based on direction
anime({
targets: mainContent,
translateX:
slideOutDirection === "right" ? ["0%", "100%"] : ["0%", "-100%"],
duration: 600,
easing: "easeInOutCubic",
delay: 200,
complete: function () {
// Navigate after animation completes
window.location.href = link.href;
},
});
}
});
}
} else {
// Non-index pages (including resume.html): slide in from right
const mainContent = document.querySelector(".main-content");
if (mainContent) {
// Reset position first (important for browser back/forward)
mainContent.style.transform = "translateX(100%)";
mainContent.classList.add("slide-in-from-right");
// Force reflow
void mainContent.offsetHeight;
// Animate in from right
anime({
targets: mainContent,
translateX: ["100%", "0%"],
// opacity: [0, 1],
duration: 800,
easing: "easeInOutCubic",
delay: 100,
});
// Handle internal link clicks for slide-out
document.addEventListener("click", function (e) {
const link = e.target.closest("a");
if (
link &&
link.href &&
link.href.includes(window.location.origin) &&
(!link.href.includes("#") || link.href.includes("index.html")) &&
!link.getAttribute("href").startsWith("#")
) {
e.preventDefault();
// Save current section before navigating
saveCurrentSection();
// Determine slide direction based on destination
const isGoingToIndex =
link.href.includes("index.html") || link.href.endsWith("/");
const slideOutDirection = isGoingToIndex ? "right" : "left";
// Fade out nav first
if (nav) {
anime({
targets: nav,
opacity: [0],
translateY: [-20],
duration: 300,
easing: "easeInOutCubic",
});
}
// Slide out based on direction
anime({
targets: mainContent,
translateX:
slideOutDirection === "right" ? ["0%", "100%"] : ["0%", "-100%"],
duration: 600,
easing: "easeInOutCubic",
delay: 200,
complete: function () {
// Navigate after animation completes
window.location.href = link.href;
},
});
}
});
}
}
// Hide contact bar on scroll
window.addEventListener("scroll", function () {
const div = document.getElementById("contactDiv");
if (div && div.classList.contains("show")) {
toggleContactBar(true);
}
});
// Reveal animation on scroll
const reveals = document.querySelectorAll(".reveal");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("active");
}
});
},
{
threshold: 0.1, // Trigger when 10% of element is visible
rootMargin: "0px 0px -50px 0px", // Trigger 50px before element enters viewport
},
);
reveals.forEach((reveal) => {
observer.observe(reveal);
});
// Lightbox functionality for gallery pages
function initLightbox() {
const lightbox = document.getElementById("lightbox");
if (!lightbox) return;
let group = null;
let items = [];
let current = 0;
let targetSize = { width: 0, height: 0 };
const content = document.getElementById("lightbox-content");
const closeBtn = document.getElementById("lightbox-close");
const prevBtn = document.getElementById("lightbox-prev");
const nextBtn = document.getElementById("lightbox-next");
// Preload all images in the group and calculate the largest dimension
function preloadAndCalculateSize(groupItems) {
let maxWidth = 0;
let maxHeight = 0;
let loaded = 0;
const total = groupItems.length;
return new Promise((resolve) => {
groupItems.forEach((item) => {
if (item.tagName === "IMG") {
const img = new window.Image();
img.onload = function () {
maxWidth = Math.max(maxWidth, img.naturalWidth);
maxHeight = Math.max(maxHeight, img.naturalHeight);
loaded++;
if (loaded === total) {
const largerDimension = Math.max(maxWidth, maxHeight);
targetSize = {
width: largerDimension,
height: largerDimension,
};
resolve();
}
};
img.onerror = function () {
loaded++;
if (loaded === total) {
const largerDimension = Math.max(maxWidth, maxHeight);
targetSize = {
width: largerDimension,
height: largerDimension,
};
resolve();
}
};
img.src = item.src;
} else if (item.tagName === "VIDEO") {
// Use a default size for videos
maxWidth = Math.max(maxWidth, 1920);
maxHeight = Math.max(maxHeight, 1080);
loaded++;
if (loaded === total) {
const largerDimension = Math.max(maxWidth, maxHeight);
targetSize = { width: largerDimension, height: largerDimension };
resolve();
}
}
});
});
}
function show(index) {
current = index;
const el = items[index];
// Add fade-out animation for content
content.style.opacity = "0";
content.style.transform = "scale(0.95)";
setTimeout(() => {
content.innerHTML = "";
// Create a wrapper for sizing and centering only
const wrapper = document.createElement("div");
wrapper.style.width = `${targetSize.width}px`;
wrapper.style.height = `${targetSize.height}px`;
wrapper.style.maxWidth = "90vw";
wrapper.style.maxHeight = "80vh";
wrapper.className = "flex items-center justify-center";
// Add click handler to close lightbox
wrapper.addEventListener("click", function (e) {
// Prevent closing if clicking navigation or close buttons
if (
e.target === prevBtn ||
e.target === nextBtn ||
e.target === closeBtn
) {
return;
}
close();
});
if (el.tagName === "IMG") {
const img = document.createElement("img");
img.src = el.src;
img.alt = el.alt;
img.className = "object-contain max-w-full max-h-full rounded";
wrapper.appendChild(img);
} else if (el.tagName === "VIDEO") {
const video = document.createElement("video");
video.src = el.src;
video.muted = true;
video.loop = true;
video.playsInline = true;
video.className = "object-contain max-w-full max-h-full rounded";
wrapper.appendChild(video);
video.play();
}
content.appendChild(wrapper);
// Add fade-in animation
setTimeout(() => {
content.style.opacity = "1";
content.style.transform = "scale(1)";
}, 50);
}, 150);
prevBtn.classList.toggle("hidden", current === 0);
nextBtn.classList.toggle("hidden", current === items.length - 1);
lightbox.classList.remove("hidden");
}
document.querySelectorAll("[data-lightbox]").forEach((el) => {
el.style.cursor = "pointer";
el.addEventListener("click", function () {
group = el.getAttribute("data-lightbox");
items = Array.from(
document.querySelectorAll('[data-lightbox="' + group + '"]'),
);
preloadAndCalculateSize(items).then(() => {
show(items.indexOf(el));
});
});
});
function close() {
// Add fade-out animation
content.style.opacity = "0";
content.style.transform = "scale(0.95)";
setTimeout(() => {
lightbox.classList.add("hidden");
content.innerHTML = "";
content.style.opacity = "";
content.style.transform = "";
}, 300);
}
closeBtn.addEventListener("click", close);
lightbox.addEventListener("click", (e) => {
if (e.target === lightbox) close();
});
prevBtn.addEventListener("click", (e) => {
e.stopPropagation();
if (current > 0) show(current - 1);
});
nextBtn.addEventListener("click", (e) => {
e.stopPropagation();
if (current < items.length - 1) show(current + 1);
});
document.addEventListener("keydown", (e) => {
if (lightbox.classList.contains("hidden")) return;
if (e.key === "Escape") close();
if (e.key === "ArrowLeft" && current > 0) show(current - 1);
if (e.key === "ArrowRight" && current < items.length - 1)
show(current + 1);
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initLightbox);
} else {
initLightbox();
}
// Add click-anywhere scroll functionality for the first viewport (index page only)
if (isIndexPage) {
const overlay = document.getElementById("viewport-click-overlay");
const projectsBtn = document.getElementById("projectsbutton");
function updateOverlay() {
if (window.scrollY === 0) {
overlay.style.pointerEvents = "auto";
if (projectsBtn) projectsBtn.style.transform = "translateY(0)";
} else {
overlay.style.pointerEvents = "none";
if (projectsBtn) projectsBtn.style.transform = "translateY(-100px)";
}
}
updateOverlay();
window.addEventListener("scroll", updateOverlay);
overlay.addEventListener("click", function () {
const targetSection = document.getElementById("sparkle-labs");
if (targetSection) {
targetSection.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
}
// Add click-to-scroll functionality for Sparkle Labs hero section
const sparkleHeroSection = document.getElementById("sparkle-hero-section");
if (sparkleHeroSection) {
sparkleHeroSection.addEventListener("click", function (e) {
// Don't scroll if clicking on nav buttons
const nav = document.querySelector("nav");
if (nav && nav.contains(e.target)) {
return;
}
// Scroll down 100vh
window.scrollBy({
top: window.innerHeight,
behavior: "smooth",
});
});
}
}
// Setup contact bar and events
document.addEventListener("DOMContentLoaded", function () {
initializePageAnimations();
initializeRightArrowScroll();
initializeDownArrowScroll();
});
// Handle browser back/forward navigation
window.addEventListener("pageshow", function (event) {
// Only reinitialize animations if coming from cache
if (event.persisted) {
initializePageAnimations();
}
});
// Note: Slide-out animations during browser forward/back navigation are not
// reliably supported due to browser performance optimizations. The browser
// may terminate JavaScript execution before animations can complete.
// Right arrow navigation scroll behavior
function initializeRightArrowScroll() {
const rightArrow = document.querySelector(".right-arrow-nav");
if (!rightArrow) return;
function handleScroll() {
const scrollHeight = document.documentElement.scrollHeight;
const clientHeight = document.documentElement.clientHeight;
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// Show arrow after scrolling 100% of viewport height
const showThreshold = clientHeight / 2;
if (scrollTop > showThreshold) {
rightArrow.classList.add("visible");
} else {
rightArrow.classList.remove("visible");
}
}
// Initial check
handleScroll();
// Listen for scroll events
window.addEventListener("scroll", handleScroll, { passive: true });
}
// Down arrow navigation scroll behavior
function initializeDownArrowScroll() {
// Create down arrow element if placeholder exists
const placeholder = document.getElementById("down-arrow-placeholder");
if (placeholder) {
placeholder.innerHTML = `
<div class="down-arrow-nav">
<svg width="59.068542" height="68.325569" viewBox="0 0 59.068542 68.325569" version="1.1"
class="w-8 h-8 text-accent hover:text-active"
xmlns="http://www.w3.org/2000/svg">
<g transform="translate(-20.473987,-20.89831)">
<path
style="fill:none;stroke:currentColor;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:bevel;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
d="M 50.008257,22.14831 V 87.973876" />
<path
style="fill:none;stroke:currentColor;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:stroke fill markers"
d="M 78.292529,59.689608 50.008258,87.973879 21.723987,59.689608" />
</g>
</svg>
</div>
`;
}
const downArrow = document.querySelector(".down-arrow-nav");
if (!downArrow) return;
// Check if we're on index page
const isIndexPage =
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html");
// Track if user has scrolled during this session
let hasScrolled = false;
function handleScroll() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// Mark that user has scrolled
if (scrollTop > 50) {
hasScrolled = true;
downArrow.classList.add("flipped");
} else {
// At top of page
if (hasScrolled && !isIndexPage) {
// User has scrolled before and returned to top - show back arrow (only on non-index pages)
downArrow.classList.remove("flipped");
downArrow.classList.add("back");
} else {
// User hasn't scrolled yet OR on index page - show down arrow
downArrow.classList.remove("flipped", "back");
}
}
}
// Initial check - show by default at top (not flipped)
downArrow.classList.add("visible");
// Listen for scroll events
window.addEventListener("scroll", handleScroll, { passive: true });
// Add click handler with different behavior based on state
downArrow.addEventListener("click", function () {
if (downArrow.classList.contains("back") && !isIndexPage) {
// If showing back arrow and NOT on index page, go back in history
window.history.back();
} else if (downArrow.classList.contains("flipped")) {
// If flipped (pointing up), scroll to top
window.scrollTo({
top: 0,
behavior: "smooth",
});
} else {
// If pointing down, scroll down 100vh
window.scrollBy({
top: window.innerHeight,
behavior: "smooth",
});
}
});
}