-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
194 lines (167 loc) · 6.59 KB
/
Copy pathscript.js
File metadata and controls
194 lines (167 loc) · 6.59 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
/* ============================================
DOUBLE-E STUDIO — script.js
============================================ */
(function () {
'use strict';
/* ─── Navbar scroll behaviour ────────────── */
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 30);
}, { passive: true });
/* ─── Hamburger menu ─────────────────────── */
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
if (hamburger && navLinks) {
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('open');
navLinks.classList.toggle('open');
});
// Close when a link is clicked
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('open');
navLinks.classList.remove('open');
});
});
}
/* ─── Scroll-triggered fade-in ───────────── */
const fadeEls = document.querySelectorAll('.fade-in, .app-card, .team-card, .studio-contact-card, .connect-card, .form-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Slight stagger for sibling elements
const siblings = [...entry.target.parentElement.children];
const idx = siblings.indexOf(entry.target);
entry.target.style.transitionDelay = (idx * 0.08) + 's';
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.08,
rootMargin: '0px 0px -40px 0px'
});
fadeEls.forEach(el => observer.observe(el));
/* ─── Floating particles ─────────────────── */
const container = document.getElementById('particles');
if (container) {
const PARTICLE_COUNT = 28;
const colors = ['rgba(124,58,237,0.5)', 'rgba(59,130,246,0.4)', 'rgba(34,197,94,0.35)', 'rgba(167,139,250,0.45)'];
for (let i = 0; i < PARTICLE_COUNT; i++) {
const p = document.createElement('div');
p.className = 'particle';
const size = Math.random() * 3 + 1.5;
const color = colors[Math.floor(Math.random() * colors.length)];
const left = Math.random() * 100;
const dur = Math.random() * 14 + 10;
const delay = Math.random() * 18;
p.style.cssText = `
width:${size}px;
height:${size}px;
background:${color};
left:${left}%;
animation-duration:${dur}s;
animation-delay:-${delay}s;
border-radius:50%;
`;
container.appendChild(p);
}
}
/* ─── Smooth anchor scroll ───────────────── */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const id = anchor.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (target) {
e.preventDefault();
const top = target.getBoundingClientRect().top + window.scrollY - 80;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});
/* ─── Tilt effect on app cards ───────────── */
document.querySelectorAll('.app-card').forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
const dx = (e.clientX - cx) / (rect.width / 2);
const dy = (e.clientY - cy) / (rect.height / 2);
const maxRot = 3;
card.style.transform = `perspective(1000px) rotateY(${dx * maxRot}deg) rotateX(${-dy * maxRot}deg) translateY(-6px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
});
});
/* ─── Count-up animation for hero stats ──── */
(function initCountUp() {
const counters = document.querySelectorAll('.stat-value[data-target]');
if (!counters.length) return;
const DURATION = 1600; // ms
const DELAY = 400; // wait a bit after page load
function easeOutQuart(t) {
return 1 - Math.pow(1 - t, 4);
}
function animateCounter(el) {
const target = parseInt(el.dataset.target, 10);
const suffix = el.dataset.suffix || '';
const start = performance.now() + DELAY;
function step(now) {
const elapsed = Math.max(0, now - start);
const progress = Math.min(elapsed / DURATION, 1);
const value = Math.round(easeOutQuart(progress) * target);
el.textContent = value + suffix;
if (progress < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
// Trigger once the hero brand becomes visible
const heroBrand = document.querySelector('.hero-brand');
if (!heroBrand) return;
const heroObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
counters.forEach(animateCounter);
heroObserver.disconnect();
}
});
}, { threshold: 0.3 });
heroObserver.observe(heroBrand);
})();
/* ─── Active nav link highlight ───────────── */
(function initActiveNav() {
const path = window.location.pathname;
const isContact = path.endsWith('contact.html');
const allNavLinks = document.querySelectorAll('.nav-links a:not(.nav-cta)');
function clearActive() {
allNavLinks.forEach(a => a.classList.remove('active'));
}
function setActive(href) {
clearActive();
allNavLinks.forEach(a => {
if (a.getAttribute('href') === href) a.classList.add('active');
});
}
// Contact page: always highlight Contact, no scroll tracking needed
if (isContact) {
setActive('contact.html');
return;
}
// Index page: switch between Home and Projects based on scroll position
const appsSection = document.getElementById('apps');
function updateScroll() {
if (appsSection && window.scrollY >= appsSection.offsetTop - 150) {
setActive('#apps');
} else {
setActive('index.html');
}
}
updateScroll();
window.addEventListener('scroll', updateScroll, { passive: true });
})();
/* ─── Micro-copy year updater ─────────────── */
document.querySelectorAll('.year').forEach(el => {
el.textContent = new Date().getFullYear();
});
})();