-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (67 loc) · 1.54 KB
/
Copy pathscript.js
File metadata and controls
73 lines (67 loc) · 1.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let galleryarray = [
{
id: 1,
name: "پرتقال",
src: "./images/Orange.jpg",
},
{
id: 2,
name: "نان",
src: "./images/Bread.jpg",
},
{
id: 3,
name: "نوشیدنی",
src: "./images/Drinks.jpg",
},
{
id: 4,
name: "ماکارونی",
src: "./images/Pasta.jpg",
},
{
id: 5,
name: "سبزیجات",
src: "./images/Vegetables.jpg",
},
{
id: 6,
name: "شیرینی ها",
src: "./images/Sweets.jpg",
},
];
let filterarray = [];
function showgallery(currarray) {
const cardElement = document.getElementById("card");
const paraElement = document.getElementById("para");
if (currarray.length === 0) {
cardElement.innerHTML = "";
paraElement.style.display = "block";
return;
}
paraElement.style.display = "none";
let cardHTML = "";
currarray.forEach((item) => {
cardHTML += `
<div class="col-md-4 card-item">
<div class="card">
<div class="img-wrapper">
<img src="${item.src}" width="100%" height="320px"/>
</div>
<span class="text-center p-2 d-flex justify-content-center align-items-center">${item.name}</span>
</div>
</div>
`;
});
cardElement.innerHTML = cardHTML;
}
document.getElementById("myinput").addEventListener("keyup", function (e) {
let text = e.target.value;
let filtered = galleryarray.filter((item) => item.name.includes(text));
if (text === "") {
showgallery(galleryarray);
} else {
showgallery(filtered);
}
});
showgallery(galleryarray);