-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
181 lines (148 loc) · 5.18 KB
/
script.js
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
// Theme Toggle
const themeToggle = document.querySelector('.theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
const icon = themeToggle.querySelector('i');
icon.classList.toggle('fa-moon');
icon.classList.toggle('fa-sun');
});
// Mobile Menu Toggle
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Smooth Scroll
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'
});
// Close mobile menu if open
navLinks.classList.remove('active');
hamburger.classList.remove('active');
}
});
});
// 3D Animated Background
const createBackground = () => {
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('hero-background').appendChild(renderer.domElement);
// Create gradient particles
const geometry = new THREE.BufferGeometry();
const particles = 5000;
const positions = new Float32Array(particles * 3);
const colors = new Float32Array(particles * 3);
for (let i = 0; i < particles * 3; i += 3) {
positions[i] = (Math.random() - 0.5) * 10;
positions[i + 1] = (Math.random() - 0.5) * 10;
positions[i + 2] = (Math.random() - 0.5) * 10;
colors[i] = Math.random();
colors[i + 1] = Math.random();
colors[i + 2] = Math.random();
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 0.05,
vertexColors: true,
transparent: true,
opacity: 0.8
});
const points = new THREE.Points(geometry, material);
scene.add(points);
camera.position.z = 5;
// Animation
const animate = () => {
requestAnimationFrame(animate);
points.rotation.x += 0.001;
points.rotation.y += 0.001;
renderer.render(scene, camera);
};
animate();
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
};
// Initialize background when the page loads
window.addEventListener('load', createBackground);
// Skill bars animation
const observeSkills = () => {
const skillBars = document.querySelectorAll('.progress');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const width = entry.target.parentElement.parentElement.querySelector('.skill-info span:last-child').textContent;
entry.target.style.width = width;
}
});
}, { threshold: 0.5 });
skillBars.forEach(bar => observer.observe(bar));
};
// Initialize skill bars animation
observeSkills();
// Form submission handling
const contactForm = document.querySelector('.contact-form');
const formStatus = document.createElement('div');
formStatus.className = 'form-status';
contactForm.insertBefore(formStatus, contactForm.firstChild);
async function submitForm(formData) {
// This is where you would typically send the data to your server
// For demonstration, we'll simulate an API call
return new Promise((resolve) => {
setTimeout(() => {
resolve({
success: true,
message: 'Message sent successfully!'
});
}, 2000);
});
}
async function handleFormSubmission(e) {
e.preventDefault();
// Show submitting status
formStatus.className = 'form-status submitting';
formStatus.textContent = 'Submitting...';
// Collect form data
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData.entries());
try {
// Submit form data
const result = await submitForm(data);
if (result.success) {
// Show success message
formStatus.className = 'form-status success';
formStatus.textContent = 'Message sent successfully!';
// Reset form
contactForm.reset();
// Show thank you message after a delay
setTimeout(() => {
formStatus.textContent = 'Thank you for your message! We will get back to you soon.';
// Clear the status message after 5 seconds
setTimeout(() => {
formStatus.style.display = 'none';
}, 5000);
}, 2000);
} else {
throw new Error(result.message || 'Failed to send message');
}
} catch (error) {
// Show error message
formStatus.className = 'form-status error';
formStatus.textContent = 'Failed to send message. Please try again later.';
}
}
if (contactForm) {
contactForm.addEventListener('submit', handleFormSubmission);
}