-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokedex.html
252 lines (220 loc) · 5.75 KB
/
pokedex.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pokedex</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="style.css" />
</head>
<style>
@import url("https://fonts.googleapis.com/css2?family=Sniglet&display=swap");
body {
font-family: "Sniglet", cursive;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
background-image: linear-gradient(to right, #ff825f 0%, #ffe667);
}
h1 {
color: #fff;
letter-spacing: 5px;
text-transform: uppercase;
text-shadow: 4px 3px 6px rgba(0, 0, 0, 1);
}
.search {
position: relative;
}
.searchInput {
font-family: inherit;
background-color: transparent;
border: none;
font-size: 16px;
padding: 15px;
height: 10px;
width: 15px;
border-radius: 10px;
transition: width 0.8s ease;
}
.searchInput,
.searchBtn:focus {
outline: none;
}
.searchBtn {
background-color: #ea00ff;
border: none;
color: #fff;
font-size: 33px;
position: absolute;
top: 0;
left: 0;
border-radius: 10px;
cursor: pointer;
transition: transform 0.8s ease;
}
.search.active .searchInput {
width: 200px;
background-color: #fff;
}
.search.active .searchBtn {
transform: translateX(198px);
background-color: #fff;
color: rgb(255, 95, 255);
}
.poke-container {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
max-width: 85%;
align-items: center;
}
.pokemon {
margin: 10px;
padding: 20px;
box-shadow: rgba(0, 0, 0, 0.17) 0px -23px 25px 0px inset,
rgba(0, 0, 0, 0.15) 0px -36px 30px 0px inset,
rgba(0, 0, 0, 0.1) 0px -79px 40px 0px inset, rgba(0, 0, 0, 0.06) 0px 2px 1px,
rgba(0, 0, 0, 0.09) 0px 4px 2px, rgba(0, 0, 0, 0.09) 0px 8px 4px,
rgba(0, 0, 0, 0.09) 0px 16px 8px, rgba(0, 0, 0, 0.09) 0px 32px 16px;
color: #fefefe;
border-radius: 10px;
}
.image-container {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 75% 30% 60% 40% / 60% 40% 60% 40%;
}
.image-container img {
width: 180px;
opacity: 0.75;
transition: all 0.3s ease;
}
.pokemon:hover .image-container img{
opacity: 1;
transform: scale(1.25);
}
.poke-info {
margin-top: 20px;
}
.poke-id {
background-color: rgba(0, 0, 0, 0.3);
border-radius: 3rem;
padding: 5px 10px;
font-size: 0.85rem;
}
.poke-name {
letter-spacing: 2px;
margin: 15px 0 10px;
text-transform: capitalize;
}
.small small {
padding: 0 5px;
}
.poke-type {
margin-top: 10px;
}
</style>
<body>
<h1>Pokedex</h1>
<div class="search">
<input type="text" class="searchInput" />
<button class="searchBtn"><i class="fa-solid fa-binoculars"></i></button>
</div>
<div class="poke-container"></div>
<script>
const poke_container = document.querySelector(".poke-container");
const search = document.querySelector(".search");
const searchBtn = document.querySelector(".searchBtn");
const searchInput = document.querySelector(".searchInput");
const pokemon_count = 151;
const bg_color = {
grass: "#8BD369",
fire: "#FF603F",
water: "#3399FF",
bug: "#AABB22",
normal: "#AAAA99",
flying: "#9AA8FA",
poison: "#B76EA4",
electric: "#FFD34E",
ground: "#E2C56A",
fairy: "#F1A8EC",
psychic: "#FF6EA4",
fighting: "#C56E5C",
rock: "#C5B679",
dragon: "#7766EE",
ice: "#66CCFF",
};
searchBtn.addEventListener("click", () => {
search.classList.toggle("active");
});
searchInput.addEventListener("input", (e) => {
//console.log(searchInput.value);
const searchValue = searchInput.value.toLowerCase();
const pokemonNames = document.querySelectorAll(".poke-name");
//console.log(pokemonNames);
pokemonNames.forEach((pokemonName) => {
if (pokemonName.innerHTML.toLowerCase().includes(searchValue)) {
pokemonName.parentElement.parentElement.style.display = "block";
} else {
pokemonName.parentElement.parentElement.style.display = "none";
}
});
});
const fetchPokemons = async () => {
for (let i = 1; i < pokemon_count; i++) {
await getPokemon(i);
}
};
const getPokemon = async (id) => {
const url = `https://pokeapi.co/api/v2/pokemon/${id}`;
const res = await fetch(url);
const data = await res.json();
//console.log(data);
createPokemonCard(data);
};
const createPokemonCard = (pokemon) => {
const pokemonDiv = document.createElement("div");
pokemonDiv.classList.add("pokemon");
const pokemonId = pokemon.id.toString().padStart(3, "0");
//console.log(pokemonId);
const pokemonType = pokemon.types[0].type.name;
const pokemonBg = bg_color[pokemonType];
pokemonDiv.style.backgroundColor = `${pokemonBg}`;
const pokemonDivInnerHTML = `
<div class="image-container">
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png"
alt="First Pokemon"
/>
</div>
<div class="poke-info">
<span class="poke-id">#${pokemonId}</span>
<h3 class="poke-name">${pokemon.name}</h3>
<div class="small">
<small class="poke-exp">
<i class="fa solid fa-flask"> </i> ${pokemon.base_experience} Exp
</small>
<small class="poke-weight">
<i class="fa-solid fa-weight-scale"></i> ${pokemon.weight} Kg
</small>
</div>
<div class="poke-type">
<i class="fa-brands fa-uncharted"></i> ${pokemonType}
</div>
</div>
`;
pokemonDiv.innerHTML = pokemonDivInnerHTML;
poke_container.appendChild(pokemonDiv);
};
fetchPokemons();
</script>
</body>
</html>