forked from souvik-maity/StyleCart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalogue.js
More file actions
32 lines (25 loc) · 1.15 KB
/
catalogue.js
File metadata and controls
32 lines (25 loc) · 1.15 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
document.addEventListener("DOMContentLoaded", () => {
const buttons = document.querySelectorAll(".filter-btn");
const catalogue = document.querySelector(".catalogue");
buttons.forEach(button => {
button.addEventListener("click", () => {
const category = button.getAttribute("data-category");
const selectedSection = document.querySelector(`.category[data-category="${category}"]`);
if (category === "all") {
resetOrder();
return;
}
if (selectedSection) {
catalogue.prepend(selectedSection); // Move selected section to the top
window.scrollTo({ top: selectedSection.offsetTop - 50, behavior: "smooth" }); // Smooth scroll
// Add animation effect
selectedSection.style.transform = "scale(1.05)";
setTimeout(() => selectedSection.style.transform = "scale(1)", 300);
}
});
});
function resetOrder() {
const allSections = document.querySelectorAll(".category");
allSections.forEach(section => catalogue.appendChild(section));
}
});