-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
361 lines (308 loc) · 9.38 KB
/
script.js
File metadata and controls
361 lines (308 loc) · 9.38 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
'use strict';
// Selected elements
const backToTopButton = document.querySelector('.back-to-top');
const heroSection = document.querySelector('.hero');
const loaderContainer = document.querySelector('.loader-container');
const logo = document.querySelector('.logo');
const topEl = document.querySelector('.top');
const navLinks = document.querySelectorAll('.nav-ul li a');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-ul li a');
const openMenuBtn = document.querySelector('.hamburger');
const closeBtn = document.querySelector('.close-btn');
const openMenuDiv = document.querySelectorAll('.hamburger div.bar');
const closeBtnDiv = document.querySelectorAll('.close-btn div.bar');
const lightBtn = document.querySelector('#light-btn');
const darkBtn = document.querySelector('#dark-btn');
const lightBtn1 = document.querySelector('#light-btn1');
const darkBtn1 = document.querySelector('#dark-btn1');
const mobileNav = document.querySelector('.mobile-navigation');
const bodyContainer = document.querySelector('.body-container');
const arrowIcon = document.querySelector('.arrow');
const entryMedia = document.querySelectorAll('.entry__media');
const socialAfter = document.querySelectorAll('.social-links li');
const contactAfter = document.querySelectorAll('.contact-social-links li');
// Lenis smooth scrolling
const lenis = new Lenis();
lenis.on('scroll', ScrollTrigger.update)
gsap.ticker.add((time) => {
lenis.raf(time * 1000)
})
gsap.ticker.lagSmoothing(0)
// Smooth scroll implementation
const smoothScroll = function (e) {
e.preventDefault();
try {
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (!targetSection) {
console.warn(`Target section ${targetId} not found`);
return;
}
lenis.scrollTo(targetSection, {
offset: 0,
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t))
});
if (mobileNav.classList.contains('active')) {
mobileNav.classList.remove('active');
}
} catch (error) {
console.error('Error during smooth scroll:', error);
}
}
navLinks.forEach(link => {
link.addEventListener('click', smoothScroll);
});
mobileNavLinks.forEach(link => {
link.addEventListener('click', smoothScroll);
});
// Back to top button functionality
const toggleBackToTopButton = () => {
const heroBottom = heroSection.offsetTop + heroSection.offsetHeight;
const scrollPosition = window.scrollY;
if (scrollPosition > heroBottom) {
backToTopButton.classList.remove('hidden');
} else {
backToTopButton.classList.add('hidden');
}
};
const scrollToTop = () => {
lenis.scrollTo(0, {
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t))
});
};
window.addEventListener('scroll', toggleBackToTopButton);
backToTopButton.addEventListener('click', scrollToTop);
// Open and close mobile navigation
openMenuBtn.addEventListener('click', function () {
mobileNav.classList.add('active');
})
closeBtn.addEventListener('click', function () {
mobileNav.classList.remove('active');
})
// Animated cursor
const words = ['my Craft', 'my Canvas', 'my Language', 'my Joy', 'my Escape', 'what I do'];
// Main timeline
const mainTimeline = gsap.timeline({
repeat: -1
})
// For each word, create a new timeline, use the Text plugin, then append that timeline to the main one
words.forEach(word => {
let textTimeline = gsap.timeline({
repeat: 1,
yoyo: true,
repeatDelay: 6
})
textTimeline.to('#typewriter', {
text: word,
duration: 1,
onUpdate: () => {
cursorTimeline.restart()
cursorTimeline.pause()
},
onComplete: () => {
cursorTimeline.play()
}
})
mainTimeline.add(textTimeline)
})
// Blinking cursor
let cursorTimeline = gsap.timeline({
repeat: -1,
repeatDelay: .8
})
cursorTimeline.to('#cursor', {
opacity: 1,
duration: 0
}).to('#cursor', {
opacity: 0,
duration: 0,
delay: .8
})
// Magneto button animation
const magneto = document.querySelector('.magneto');
const magnetoText = document.querySelector('.magneto .text');
const activateMagneto = (event) => {
let boundBox = magneto.getBoundingClientRect();
const magnetoStrength = 40;
const magnetoTextStrength = 80;
const newX = ((event.clientX - boundBox.left)/magneto.offsetWidth) - 0.5;
const newY = ((event.clientY - boundBox.top)/magneto.offsetHeight) - 0.5;
// Move the button to its new position
gsap.to(magneto, {
duration: 1,
x: newX * magnetoStrength,
y: newY * magnetoStrength,
ease: Power4.easeOut
})
// Move the button to its new position
gsap.to(magnetoText, {
duration: 1,
x: newX * magnetoTextStrength,
y: newY * magnetoTextStrength,
ease: Power4.easeOut
})
}
// Mouse leave stuff
const resetMagneto = (event) => {
// Move the button to its default position
gsap.to(magneto, {
duration: 1,
x: 0,
y: 0,
ease: "Elastic.easeOut"
})
// Move the button text to its default position
gsap.to(magnetoText, {
duration: 1,
x: 0,
y: 0,
ease: "Elastic.easeOut"
})
}
magneto.addEventListener('mousemove', activateMagneto);
magneto.addEventListener('mouseleave', resetMagneto);
magneto.addEventListener('click', smoothScroll);
// Appear Animations
gsap.set(['.hero-h1', '#hero-h3', '#hero-p', '.social-links-li'], {
scale: 0,
opacity: 0,
transformOrigin: '50% 50%'
});
const tl = gsap.timeline({
duration: 1.2
});
tl.fromTo('.logo', {
y: -100
}, {
y: 0,
ease: "bounce"
}).fromTo('.nav-ul li', {
y: -100,
ease: "bounce"
}, {
y: 0,
ease: "bounce"
}, '>').fromTo('.hamburger', {
y: -100,
ease: "bounce"
}, {
y: 0,
ease: "bounce"
}, '>').fromTo('.header-side-content', {
y: -100
}, {
y: 0,
ease: "bounce"
}, '>').to('.hero-h1', {
scale: 1,
opacity: 1,
duration: 1.2,
ease: "power2ease.out"
}, '>')
tl.to('#hero-h3', {
scale: 1,
opacity: 1,
duration: 1.2,
ease: "power2ease.out"
})
tl.to('#hero-p', {
scale: 1,
opacity: 1,
duration: 1.2,
ease: "power2ease.out"
})
tl.to('.social-links-li', {
rotation: 360,
scale: 1,
opacity: 1,
duration: 1.2,
ease: "power3ease.out"
},'>')
tl.fromTo('.magneto', {
opacity: 0,
duration: 1.2,
ease: "power2ease.out"
}, {
opacity: 1,
duration: 1.2,
ease: "power2ease.out"
}, '>')
tl.fromTo('.about-me-container', {
opacity: 0,
duration: 1.2,
ease: "power2ease.out"
}, {
opacity: 1,
duration: 1.2,
ease: "power2ease.out"
}, '>')
// ScrollIntoView Animation
const entries = document.querySelectorAll('.entry');
entries.forEach(entry => {
let entryMeta = entry.querySelector('.entry__meta');
let entryMedia = entry.querySelector('.entry__media');
let entriesTimeline = gsap.timeline({
scrollTrigger: {
trigger: entry,
start: 'top bottom',
end: 'bottom 90%',
scrub: true,
// markers: true
}
})
entriesTimeline.fromTo(entryMeta, {
xPercent: -100,
opacity: 0
}, {
xPercent: 0,
opacity: 1
})
entriesTimeline.fromTo(entryMedia, {
xPercent: 100,
opacity: 0
}, {
xPercent: 0,
opacity: 1
}, '<')
})
// Theme switcher
const darkElements = [bodyContainer, arrowIcon, magneto, logo, topEl];
const toggleTheme = (theme) => {
if (theme === 'dark') {
darkElements.forEach(el => el.classList.add('dark'));
openMenuDiv.forEach(div => div.classList.add('dark'));
closeBtnDiv.forEach(div => div.classList.add('dark'));
entryMedia.forEach(entry => entry.classList.add('dark'));
socialAfter.forEach(after => after.classList.add('dark'));
contactAfter.forEach(after => after.classList.add('dark'));
darkBtn.style.display = 'none';
lightBtn.style.display = 'block';
darkBtn1.style.display = 'none';
lightBtn1.style.display = 'block';
} else {
darkElements.forEach(el => el.classList.remove('dark'));
openMenuDiv.forEach(div => div.classList.remove('dark'));
closeBtnDiv.forEach(div => div.classList.remove('dark'));
entryMedia.forEach(entry => entry.classList.remove('dark'));
socialAfter.forEach(after => after.classList.remove('dark'));
contactAfter.forEach(after => after.classList.remove('dark'));
lightBtn.style.display = 'none';
darkBtn.style.display = 'block';
lightBtn1.style.display = 'none';
darkBtn1.style.display = 'block';
}
localStorage.setItem('theme', theme);
}
darkBtn.addEventListener('click', () => toggleTheme('dark'));
lightBtn.addEventListener('click', () => toggleTheme('light'));
darkBtn1.addEventListener('click', () => toggleTheme('dark'));
lightBtn1.addEventListener('click', () => toggleTheme('light'));
document.addEventListener('DOMContentLoaded', function() {
const currentTheme = localStorage.getItem('theme') || 'light';
setTimeout(() => {
loaderContainer.style.display = 'none';
}, 1200);
toggleTheme(currentTheme);
});