-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
58 lines (52 loc) · 1.88 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
// Light/Dark Mode Toggle
const themeToggle = document.getElementById('theme-toggle');
const body = document.getElementById('main-body');
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
const icon = themeToggle.querySelector('i');
icon.classList.toggle('fa-sun');
icon.classList.toggle('fa-moon');
});
// AJAX Form Submission
document.getElementById('contact-form').addEventListener('submit', function (e) {
e.preventDefault();
const formData = new FormData(this);
fetch('https://your-backend-api-url.com/contact', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
document.getElementById('form-response').textContent = 'Message sent successfully!';
})
.catch(error => {
document.getElementById('form-response').textContent = 'Error sending message.';
});
});
// Project Filtering
const projectCards = document.querySelectorAll('.project-card');
const filterButtons = document.querySelectorAll('.filter-btn');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const filter = button.getAttribute('data-filter');
projectCards.forEach(card => {
if (filter === 'all' || card.getAttribute('data-category') === filter) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
});
});
// Project Search
document.getElementById('project-search').addEventListener('input', function () {
const searchValue = this.value.toLowerCase();
projectCards.forEach(card => {
const projectName = card.querySelector('h3').textContent.toLowerCase();
if (projectName.includes(searchValue)) {
card.style.display = 'block';
} else {
card.style.display = 'none';
}
});
});