Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong-Jing-Yu authored Nov 10, 2024
1 parent d6a73f4 commit 2d1e07e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions js/plugins/TagFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 获取所有筛选按钮和博客卡片
const filterButtons = document.querySelectorAll(".filter-button");
const blogCards = document.querySelectorAll(".blog-card");

// 添加事件监听器到每个筛选按钮上
filterButtons.forEach(button => {
button.addEventListener("click", () => {
// 获取选中的标签
const selectedTag = button.getAttribute("data-tag");

// 切换按钮的选中状态
filterButtons.forEach(btn => btn.classList.remove("selected"));
button.classList.add("selected");

// 过滤博客卡片
blogCards.forEach(card => {
const tags = card.getAttribute("data-tags").split(",");

if (selectedTag === "all" || tags.includes(selectedTag)) {
card.style.display = "block";
} else {
card.style.display = "none";
}
});
});
});

0 comments on commit 2d1e07e

Please sign in to comment.