-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (130 loc) · 6.02 KB
/
script.js
File metadata and controls
155 lines (130 loc) · 6.02 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
// Loading Animation
window.addEventListener('load', function() {
const loading = document.getElementById('loading');
setTimeout(() => {
loading.style.opacity = '0';
loading.style.visibility = 'hidden';
}, 1500);
});
// Mobile Menu Toggle
const menuToggle = document.getElementById('menuToggle');
const navLinks = document.getElementById('navLinks');
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
menuToggle.classList.toggle('fa-times');
});
// Header Scroll Effect
window.addEventListener('scroll', () => {
const header = document.getElementById('header');
if (window.scrollY > 100) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Close mobile menu when clicking on a link
const navItems = document.querySelectorAll('.nav-links a');
navItems.forEach(item => {
item.addEventListener('click', () => {
navLinks.classList.remove('active');
menuToggle.classList.remove('fa-times');
});
});
// Portfolio Filter
const filterBtns = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class from all buttons
filterBtns.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
btn.classList.add('active');
const filter = btn.getAttribute('data-filter');
portfolioItems.forEach(item => {
if (filter === 'all' || item.getAttribute('data-category').includes(filter)) {
item.style.display = 'block';
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'translateY(0)';
}, 100);
} else {
item.style.opacity = '0';
item.style.transform = 'translateY(20px)';
setTimeout(() => {
item.style.display = 'none';
}, 500);
}
});
});
});
// Animate skill bars when scrolled into view
const skillBars = document.querySelectorAll('.skill-level');
function animateSkillBars() {
skillBars.forEach(bar => {
const barPosition = bar.getBoundingClientRect().top;
const screenPosition = window.innerHeight / 1.3;
if (barPosition < screenPosition) {
const width = bar.getAttribute('data-width');
bar.style.width = width;
}
});
}
window.addEventListener('scroll', animateSkillBars);
// Scroll animations
const fadeElements = document.querySelectorAll('.fade-in, .slide-in-left, .slide-in-right, .contact-item');
function checkScroll() {
fadeElements.forEach(element => {
const elementTop = element.getBoundingClientRect().top;
const elementVisible = 150;
if (elementTop < window.innerHeight - elementVisible) {
element.classList.add('visible');
}
});
}
window.addEventListener('scroll', checkScroll);
// Initial check in case elements are already in view
checkScroll();
// Contact Form Submission with Formspree
const contactForm = document.getElementById('contactForm');
const formMessage = document.getElementById('formMessage');
contactForm.addEventListener('submit', async(e) => {
e.preventDefault();
const submitBtn = contactForm.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
// Show loading state
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
try {
const formData = new FormData(contactForm);
const response = await fetch(contactForm.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
});
if (response.ok) {
formMessage.textContent = 'Thank you! Your message has been sent successfully. I will get back to you soon.';
formMessage.className = 'form-message success';
contactForm.reset();
} else {
throw new Error('Form submission failed');
}
} catch (error) {
formMessage.textContent = 'Sorry, there was an error sending your message. Please try again or email me directly at yusufhussaini0904@gmail.com';
formMessage.className = 'form-message error';
} finally {
submitBtn.textContent = originalText;
submitBtn.disabled = false;
// Hide message after 5 seconds
setTimeout(() => {
formMessage.style.display = 'none';
}, 5000);
}
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
});