-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (48 loc) · 1.89 KB
/
Copy pathscript.js
File metadata and controls
57 lines (48 loc) · 1.89 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
// Filter functionality for projects
const filterButtons = document.querySelectorAll('.filter-btn');
const projectItems = document.querySelectorAll('.project-item');
// Add click event to each filter button
filterButtons.forEach(button => {
button.addEventListener('click', () => {
const category = button.getAttribute('data-category');
// Loop through all project items
projectItems.forEach(item => {
const itemCategory = item.getAttribute('data-category');
// Show all items if the category is "all"
if (category === 'all') {
item.style.display = 'flex'; // Show all items
} else {
// Show items matching the selected category, hide others
if (itemCategory === category) {
item.style.display = 'flex'; // Show matching item
} else {
item.style.display = 'none'; // Hide non-matching item
}
}
});
// Update active class for the buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
});
});
// Smooth Scrolling for internal links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Back to Top Button functionality
const backToTopBtn = document.getElementById('back-to-top');
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
backToTopBtn.style.display = 'block'; // Show the button
} else {
backToTopBtn.style.display = 'none'; // Hide the button
}
});
backToTopBtn.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});