-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6a73f4
commit 2d1e07e
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
}); | ||
}); | ||
}); |