Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
274 lines (241 loc) · 8.05 KB
/
Copy pathscript.js
File metadata and controls
274 lines (241 loc) · 8.05 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
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navLinks.classList.toggle('active');
});
// Close mobile menu when clicking a link
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navLinks.classList.remove('active');
});
});
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.style.padding = '10px 0';
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
} else {
navbar.style.padding = '15px 0';
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
}
});
// Smooth scroll for 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'
});
}
});
});
// Scroll animations using Intersection Observer
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Add fade-in class to elements and observe them
document.querySelectorAll('.skill-card, .project-card, .about-text, .contact-info, .stat').forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
// Animate skill progress bars when they come into view
const skillCards = document.querySelectorAll('.skill-card');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progressBar = entry.target.querySelector('.skill-progress');
if (progressBar) {
const width = progressBar.style.width;
progressBar.style.width = '0%';
setTimeout(() => {
progressBar.style.width = width;
}, 100);
}
}
});
}, { threshold: 0.5 });
skillCards.forEach(card => {
skillObserver.observe(card);
});
// Contact form handling
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const data = Object.fromEntries(formData);
// Simple validation
if (!data.name || !data.email || !data.subject || !data.message) {
showNotification('Por favor, preencha todos os campos', 'error');
return;
}
if (!isValidEmail(data.email)) {
showNotification('Por favor, insira um e-mail válido', 'error');
return;
}
// Simulate form submission
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Enviando...';
submitBtn.disabled = true;
setTimeout(() => {
showNotification('Mensagem enviada com sucesso!', 'success');
this.reset();
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}, 1500);
});
}
// Email validation helper
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Notification system
function showNotification(message, type) {
// Remove existing notification
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.innerHTML = `
<span>${message}</span>
<button class="notification-close">×</button>
`;
// Add styles
notification.style.cssText = `
position: fixed;
top: 100px;
right: 20px;
padding: 15px 20px;
border-radius: 5px;
color: white;
display: flex;
align-items: center;
gap: 10px;
z-index: 10000;
animation: slideIn 0.3s ease;
background: ${type === 'success' ? '#3d4d1e' : '#c0392b'};
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
`;
// Add animation keyframes
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
`;
document.head.appendChild(style);
// Add close button functionality
notification.querySelector('.notification-close').style.cssText = `
background: none;
border: none;
color: white;
font-size: 1.2rem;
cursor: pointer;
padding: 0;
line-height: 1;
`;
notification.querySelector('.notification-close').addEventListener('click', () => {
notification.remove();
});
document.body.appendChild(notification);
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentElement) {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}
}, 5000);
}
// Add slideOut animation
const slideOutStyle = document.createElement('style');
slideOutStyle.textContent = `
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
`;
document.head.appendChild(slideOutStyle);
// Typewriter effect for hero text
const heroSubtitle = document.querySelector('.hero-content h2');
if (heroSubtitle) {
const text = heroSubtitle.textContent;
heroSubtitle.textContent = '';
heroSubtitle.style.borderRight = '2px solid var(--accent-color)';
let i = 0;
function typeWriter() {
if (i < text.length) {
heroSubtitle.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 50);
} else {
setTimeout(() => {
heroSubtitle.style.borderRight = 'none';
}, 1000);
}
}
// Start typing after a delay
setTimeout(typeWriter, 1000);
}
// Add active state to navigation links based on scroll position
const sections = document.querySelectorAll('section[id]');
const navLinksItems = document.querySelectorAll('.nav-links a');
function highlightNavLink() {
const scrollY = window.scrollY;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navLinksItems.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', highlightNavLink);
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
// Preload animations
document.body.style.opacity = '0';
setTimeout(() => {
document.body.style.transition = 'opacity 0.5s ease';
document.body.style.opacity = '1';
}, 100);
});