Skip to content

Commit

Permalink
Create script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SukiMizuhiki authored Sep 13, 2024
1 parent 52e31c9 commit 0066269
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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';
}
});
});

0 comments on commit 0066269

Please sign in to comment.