-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
268 lines (225 loc) · 8.77 KB
/
script.js
File metadata and controls
268 lines (225 loc) · 8.77 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
// fieldCanvas Portfolio - Interactive JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Initialize the portfolio
initPortfolio();
// Add smooth scrolling for anchor links
initSmoothScrolling();
// Add intersection observer for animations
initIntersectionObserver();
// Add interactive effects
initInteractiveEffects();
// Add performance optimizations
initPerformanceOptimizations();
});
function initPortfolio() {
console.log('🎨 fieldCanvas Portfolio initialized');
// Add page transition effect
document.body.classList.add('page-transition');
// Add floating animation to main heading
const mainHeading = document.querySelector('h1');
if (mainHeading) {
mainHeading.classList.add('float-animation');
}
}
function initSmoothScrolling() {
// Smooth scroll for all anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
function initIntersectionObserver() {
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe project cards
document.querySelectorAll('.group').forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
}
function initInteractiveEffects() {
// Enhanced button hover effects
const buttons = document.querySelectorAll('a, button');
buttons.forEach(button => {
button.addEventListener('mouseenter', function() {
this.style.transform = 'scale(1.05) translateY(-2px)';
});
button.addEventListener('mouseleave', function() {
this.style.transform = 'scale(1) translateY(0)';
});
});
// Project card interactions
const projectCards = document.querySelectorAll('.group');
projectCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'scale(1.02) translateY(-8px)';
this.style.boxShadow = '0 25px 50px -12px rgba(0, 0, 0, 0.25)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'scale(1) translateY(0)';
this.style.boxShadow = '0 10px 15px -3px rgba(0, 0, 0, 0.1)';
});
});
// Add click ripple effect to buttons
addRippleEffect();
}
function addRippleEffect() {
const buttons = document.querySelectorAll('a, button');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
}
function initPerformanceOptimizations() {
// Lazy loading for images (if any are added later)
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('image-loading');
imageObserver.unobserve(img);
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
imageObserver.observe(img);
});
}
// Debounce scroll events
let scrollTimeout;
window.addEventListener('scroll', () => {
if (scrollTimeout) {
clearTimeout(scrollTimeout);
}
scrollTimeout = setTimeout(() => {
// Handle scroll-based animations here
}, 16);
});
}
// Add CSS for ripple effect
function addRippleStyles() {
const style = document.createElement('style');
style.textContent = `
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
animation: ripple-animation 0.6s linear;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
a, button {
position: relative;
overflow: hidden;
}
`;
document.head.appendChild(style);
}
// Add ripple styles when DOM is loaded
document.addEventListener('DOMContentLoaded', addRippleStyles);
// Add keyboard navigation support
document.addEventListener('keydown', function(e) {
// Tab navigation enhancement
if (e.key === 'Tab') {
document.body.classList.add('keyboard-navigation');
}
});
// Remove keyboard navigation class on mouse use
document.addEventListener('mousedown', function() {
document.body.classList.remove('keyboard-navigation');
});
// Add loading state for buttons
function addLoadingState() {
const buttons = document.querySelectorAll('a[href*="github.com"]');
buttons.forEach(button => {
button.addEventListener('click', function() {
const originalText = this.innerHTML;
this.innerHTML = '<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>Loading...';
this.disabled = true;
// Reset button after a delay (simulating loading)
setTimeout(() => {
this.innerHTML = originalText;
this.disabled = false;
}, 2000);
});
});
}
// Initialize loading states
document.addEventListener('DOMContentLoaded', addLoadingState);
// Add scroll progress indicator
function addScrollProgress() {
const progressBar = document.createElement('div');
progressBar.className = 'fixed top-0 left-0 w-full h-1 bg-blue-600 z-50 transform origin-left';
progressBar.style.transform = 'scaleX(0)';
document.body.appendChild(progressBar);
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset;
const docHeight = document.body.offsetHeight - window.innerHeight;
const scrollPercent = scrollTop / docHeight;
progressBar.style.transform = `scaleX(${scrollPercent})`;
});
}
// Initialize scroll progress
document.addEventListener('DOMContentLoaded', addScrollProgress);
// Add theme toggle functionality (for future enhancement)
function initThemeToggle() {
const themeToggle = document.createElement('button');
themeToggle.innerHTML = '🌙';
themeToggle.className = 'fixed top-4 right-4 p-3 bg-gray-800 text-white rounded-full shadow-lg hover:bg-gray-700 transition-all duration-300 z-50';
themeToggle.title = 'Toggle theme';
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
themeToggle.innerHTML = document.body.classList.contains('dark-mode') ? '☀️' : '🌙';
});
document.body.appendChild(themeToggle);
}
// Initialize theme toggle
document.addEventListener('DOMContentLoaded', initThemeToggle);
// Add console welcome message
console.log(`
🎨 Welcome to fieldCanvas Portfolio!
🚀 Built with HTML, CSS, TailwindCSS & JavaScript
⭐ Star the repo: https://github.com/CodeByAshuu/fieldCanvas
`);