-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (142 loc) · 5.12 KB
/
script.js
File metadata and controls
167 lines (142 loc) · 5.12 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
// Mobile Menu Toggle
const menuToggle = document.getElementById('menu-toggle');
const mobileMenu = document.getElementById('mobile-menu');
if (menuToggle && mobileMenu) {
menuToggle.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
}
// Form Validation and Submission
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Reset errors
const errorElements = contactForm.querySelectorAll('.error-text');
errorElements.forEach(el => el.classList.add('hidden'));
// Get form values
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const subject = document.getElementById('subject').value.trim();
const message = document.getElementById('message').value.trim();
let isValid = true;
// Validate name
if (name === '') {
document.querySelector('#name + .error-text').classList.remove('hidden');
isValid = false;
}
// Validate email
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (email === '' || !emailRegex.test(email)) {
document.querySelector('#email + .error-text').classList.remove('hidden');
isValid = false;
}
// Validate subject
if (subject === '') {
document.querySelector('#subject + .error-text').classList.remove('hidden');
isValid = false;
}
// Validate message
if (message === '') {
document.querySelector('#message + .error-text').classList.remove('hidden');
isValid = false;
}
// If form is valid, submit it
if (isValid) {
// In a real application, you would send the form data to a server here
// For this example, we'll just show a success message
const formMessage = document.getElementById('form-message');
formMessage.textContent = 'Thank you for your message! I will get back to you soon.';
formMessage.className = 'mt-4 text-center form-success';
formMessage.classList.remove('hidden');
// Reset form
contactForm.reset();
// Hide message after 5 seconds
setTimeout(() => {
formMessage.classList.add('hidden');
}, 5000);
}
});
}
// Animation on scroll
document.addEventListener('DOMContentLoaded', function() {
// Fade in elements when they come into view
const fadeElements = document.querySelectorAll('.fade-in');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('appear');
}
});
}, {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px"
});
fadeElements.forEach(element => {
observer.observe(element);
});
// Skill bar animations
const skillBars = document.querySelectorAll('.skill-progress');
skillBars.forEach(bar => {
const width = bar.style.width;
bar.style.setProperty('--target-width', width);
bar.style.width = '0';
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.width = entry.target.style.getPropertyValue('--target-width');
}
});
}, {
threshold: 0.5
});
skillObserver.observe(bar);
});
// Project card hover effect enhancement
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-10px)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0)';
});
});
});
// Smooth scrolling 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) {
window.scrollTo({
top: target.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Header scroll effect
window.addEventListener('scroll', () => {
const header = document.querySelector('header');
if (window.scrollY > 50) {
header.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)';
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.backdropFilter = 'blur(10px)';
} else {
header.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
header.style.background = 'white';
header.style.backdropFilter = 'none';
}
});
// Initialize animations on page load
document.addEventListener('DOMContentLoaded', () => {
// Add appear class to elements that are already in view
const fadeElements = document.querySelectorAll('.fade-in');
fadeElements.forEach(element => {
const rect = element.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom > 0) {
element.classList.add('appear');
}
});
});