-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (92 loc) · 3.42 KB
/
Copy pathscript.js
File metadata and controls
108 lines (92 loc) · 3.42 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
/* ============================================================
LETTERBOXD-THEMED PORTFOLIO — script.js
Author: @miabeyefendi
============================================================ */
(function () {
'use strict';
// ── Dynamic year in footer ──
const yearEl = document.getElementById('year');
if (yearEl) {
yearEl.textContent = new Date().getFullYear();
}
// ── Fade-in on scroll (Intersection Observer) ──
const fadeEls = document.querySelectorAll('.fade-in');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: '0px 0px -40px 0px' }
);
fadeEls.forEach(function (el) {
observer.observe(el);
});
} else {
// Fallback: show all immediately for older browsers
fadeEls.forEach(function (el) {
el.classList.add('visible');
});
}
// ── Active nav link highlight on scroll ──
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav__link');
if (sections.length && navLinks.length) {
var scrollTimeout;
function onScroll() {
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(function () {
var scrollY = window.scrollY || window.pageYOffset;
var active = null;
sections.forEach(function (section) {
var offsetTop = section.offsetTop - 80;
if (scrollY >= offsetTop) {
active = section.getAttribute('id');
}
});
navLinks.forEach(function (link) {
link.classList.remove('nav__link--active');
if (active && link.getAttribute('href') === '#' + active) {
link.classList.add('nav__link--active');
}
});
}, 50);
}
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
// ── Smooth scroll for all anchor links (in-page) ──
document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
anchor.addEventListener('click', function (e) {
var targetId = anchor.getAttribute('href').slice(1);
if (!targetId) return;
var target = document.getElementById(targetId);
if (!target) return;
// Only prevent default if prefers-reduced-motion is not set
var prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!prefersReduced) {
e.preventDefault();
var offset = 66; // nav height
var top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top: top, behavior: 'smooth' });
// Move focus to target for keyboard/screen reader users
target.setAttribute('tabindex', '-1');
target.focus({ preventScroll: true });
}
});
});
// ── Stagger link-card animation delay ──
var linkCards = document.querySelectorAll('.link-card');
linkCards.forEach(function (card, i) {
card.style.transitionDelay = (i * 0.035) + 's';
});
// ── Stagger project card animation delay ──
var projectCards = document.querySelectorAll('.card');
projectCards.forEach(function (card, i) {
card.style.transitionDelay = (i * 0.1) + 's';
});
}());