Posted on April 4, 2021, 8 p.m. by Bishal ( 10840)
index.html
index.html
<!DOCTYPE html>
<html>
<head>
<title>Image Gallery - Code With Bishal</title>
</head>
<!-- created by Code With Bishal - www.codewithbishal.com
-->
<body>
</body>
</html>
div
items that will work as an Image container.
<div class="picture-container">
<ul>
<li data-filter="all">ALL</li>
<li data-filter="Violet"
class="text-Violet">Violet</li>
<li data-filter="Green"
class="text-Green">Green</li>
<li data-filter="sunflower"
class="text-sunflower">SUNFLOWER</li>
</ul>
</div>
<div class="block-cover">
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
<div class="col-auto box sunflower"></div>
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
<div class="col-auto box sunflower"></div>
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
</div>
script.js
<head> </head>
of your HTML document:<script src="script.js"></script>
script.js
file:const filterBox = document.querySelectorAll(".box");
document.querySelector(".picture-container").addEventListener("click",
(event) => {
if (event.target.tagName !== "LI") return
false;
let filterClass = event.target.dataset["filter"];
filterBox.forEach((elem) => {
elem.classList.remove("hide");
if (!elem.classList.contains(filterClass) && filterClass
!==
"all") { elem.classList.add("hide"); }
});
});
style.css
<head> </head>
of your HTML document:<link href="style.css" rel="stylesheet">
style.css
file:.picture-container ul li {
display: inline-block;
padding: 10px 40px 10px 0;
cursor: pointer;
}
.box {
border-radius: 4px;
box-shadow: 6px 7px 28px 0 rgba(16, 16, 16, 0.7);
min-height: 140px;
min-width: calc(22% - 28px);
padding: 0 10px;
margin: 15px;
border-width: 3px;
float: left;
}
.box.Violet {
border: 3px solid #8e44ad;
}
.box.Green {
border: 3px solid #2ecc71;
}
.box.sunflower {
border: 3px solid #f1c40f;
}
.text-Violet {
color: #8e44ad;
}
.text-Green {
color: #2ecc71;
}
.text-sunflower {
color: #f1c40f;
}
.hide {
opacity: 1;
animation-name: slow;
animation-duration: 2s;
animation-fill-mode: forwards;
}
@keyframes slow {
to {
opacity: 0;
}
}
@media (max-width: 767px) {
.picture-container ul li {
padding: 0;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Image Gallery - Code With Bishal</title>
</head>
<!-- created by Code With Bishal - www.codewithbishal.com
-->
<body>
<div class="picture-container">
<ul>
<li data-filter="all">ALL</li>
<li data-filter="Violet"
class="text-Violet">Violet</li>
<li data-filter="Green"
class="text-Green">Green</li>
<li data-filter="sunflower"
class="text-sunflower">SUNFLOWER</li>
</ul>
</div>
<div class="block-cover">
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
<div class="col-auto box sunflower"></div>
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
<div class="col-auto box sunflower"></div>
<div class="col-auto box Violet"></div>
<div class="col-auto box Green"></div>
</div>
</body>
</html>
const filterBox = document.querySelectorAll(".box");
document.querySelector(".picture-container").addEventListener("click",
(event) => {
if (event.target.tagName !== "LI") return
false;
let filterClass = event.target.dataset["filter"];
filterBox.forEach((elem) => {
elem.classList.remove("hide");
if (!elem.classList.contains(filterClass) && filterClass
!==
"all") { elem.classList.add("hide"); }
});
});
.picture-container ul li {
display: inline-block;
padding: 10px 40px 10px 0;
cursor: pointer;
}
.box {
border-radius: 4px;
box-shadow: 6px 7px 28px 0 rgba(16, 16, 16, 0.7);
min-height: 140px;
min-width: calc(22% - 28px);
padding: 0 10px;
margin: 15px;
border-width: 3px;
float: left;
}
.box.Violet {
border: 3px solid #8e44ad;
}
.box.Green {
border: 3px solid #2ecc71;
}
.box.sunflower {
border: 3px solid #f1c40f;
}
.text-Violet {
color: #8e44ad;
}
.text-Green {
color: #2ecc71;
}
.text-sunflower {
color: #f1c40f;
}
.hide {
opacity: 1;
animation-name: slow;
animation-duration: 2s;
animation-fill-mode: forwards;
}
@keyframes slow {
to {
opacity: 0;
}
}
@media (max-width: 767px) {
.picture-container ul li {
padding: 0;
}
}