-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (143 loc) · 5.06 KB
/
script.js
File metadata and controls
167 lines (143 loc) · 5.06 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 Navigation Toggle
document.addEventListener('DOMContentLoaded', function() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', function() {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a nav link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
}
});
// Contact Form Handling
const contactForm = document.getElementById('contactForm');
const formMessage = document.getElementById('formMessage');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const name = formData.get('name');
const email = formData.get('email');
const subject = formData.get('subject');
const message = formData.get('message');
// Simple form validation
if (!name || !email || !subject || !message) {
showMessage('Please fill in all required fields.', 'error');
return;
}
if (!isValidEmail(email)) {
showMessage('Please enter a valid email address.', 'error');
return;
}
// Simulate form submission (replace with actual form handling)
showMessage('Thank you for your message! I\'ll get back to you soon.', 'success');
contactForm.reset();
});
}
// Helper function to validate email
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Helper function to show form messages
function showMessage(message, type) {
if (formMessage) {
formMessage.textContent = message;
formMessage.className = `form-message ${type}`;
// Hide message after 5 seconds
setTimeout(() => {
formMessage.style.display = 'none';
}, 5000);
}
}
// 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) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add animation to project cards on scroll
function animateOnScroll() {
const cards = document.querySelectorAll('.project-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1
});
cards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(card);
});
}
// Initialize animations when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Add slight delay to ensure all elements are rendered
setTimeout(animateOnScroll, 100);
});
// Add typing effect to hero text (optional enhancement)
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Active navigation link highlighting
function updateActiveNavLink() {
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.classList.remove('active');
const linkHref = link.getAttribute('href');
if (linkHref === currentPage || (currentPage === '' && linkHref === 'index.html')) {
link.classList.add('active');
}
});
}
// Call on page load
document.addEventListener('DOMContentLoaded', updateActiveNavLink);
// Add loading animation
window.addEventListener('load', function() {
const body = document.body;
body.classList.add('loaded');
// Add CSS for loading animation
const style = document.createElement('style');
style.textContent = `
body {
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
body.loaded {
opacity: 1;
}
`;
document.head.appendChild(style);
});
// Console message for developers
console.log('👋 Welcome to my personal website! Built with HTML, CSS, and JavaScript.');
console.log('🚀 Interested in the code? Check out the GitHub repository!');