Tthe plus sign is placed inside .pokemon-list
as a ::before
, and I need .pokemon-list
to have overflow-y: scroll
in order to be able to scroll through all the pokemons. However, the + is still getting hidden as if I had set overflow-x: hidden
which I didn’t.
Any idea of what’s happening ?
don’t pay attention to the small images not displaying, they are stored locally
const url = "https://pokeapi.co/api/v2/pokemon/";
const sprite3dElement = document.querySelector(".pokemon-3Dmodel img");
const pokemonList = document.querySelector(".pokemon-list");
const shinyButton = document.querySelector(".shiny-button");
const premierPokemon = 1;
const dernierPokemon = 151;
const nbPokemon = dernierPokemon - premierPokemon + 1;
window.addEventListener("load", getPokedata);
function getPokedata() {
const pokemonData = []; // array to store each Pokemon's data
for (let i = premierPokemon; i <= dernierPokemon; i++) {
const finalUrl = url + i;
fetch(finalUrl)
.then((response) => response.json())
.then((data) => {
pokemonData[i - premierPokemon + 1] = data; // store the data for each Pokemon in the correct order
})
.then(() => {
if (pokemonData.length === nbPokemon + 1) {
// if we have fetched all the Pokemon data, generate the cards in the correct order
pokemonData.forEach((data) => {
generateCard(data);
});
betterPokemonCards();
toggleShiny();
}
});
}
}
function generateCard(data) {
console.log(data);
const dex_number = data.id;
const name = data.name;
const sprite3D = data.sprites.other["official-artwork"].front_default;
const sprite3DShiny = data.sprites.other["official-artwork"].front_shiny;
const sprite2D = data.sprites.versions["generation-viii"].icons.front_default;
pokemonList.innerHTML += ` <li class="pokemon${
dex_number == dernierPokemon ? " pokemon-active" : ""
}" data-sprite3D="${sprite3D}" data-shiny3D="${sprite3DShiny}" data-id="${dex_number}">
<div>
<div class="pokemon__sprite">
<img src="${sprite2D}" alt="sprite">
</div>
<p class="pokemon__num">No. <span class="pokemon__num--field">${dex_number}</span></p>
</div>
<p class="pokemon__name">${name}</p>
<div class="pokeball">
<img src="images/pokeball.png" alt="pokeball">
</div>
</li>
`;
sprite3dElement.src = sprite3D;
}
function betterPokemonCards() {
let pokemons = document.querySelectorAll(".pokemon");
//adds one or two 0 to the dex number if it is less than 10 or 100
pokemons.forEach((pokemon) => {
let dex_entry =
pokemon.firstElementChild.lastElementChild.lastElementChild.innerText;
if (dex_entry.length == 1) {
pokemon.firstElementChild.lastElementChild.lastElementChild.innerText =
"00" + dex_entry;
} else if (dex_entry.length == 2) {
pokemon.firstElementChild.lastElementChild.lastElementChild.innerText =
"0" + dex_entry;
}
//adds an event listener to each pokemon so that when you click on it, it adds the class pokemon-active
pokemon.addEventListener("click", () => {
sprite3dElement.src = pokemon.getAttribute("data-sprite3D");
pokemons.forEach((pokemon) => {
pokemon.classList.remove("pokemon-active");
});
pokemon.classList.add("pokemon-active");
});
});
}
:root {
--attachment: fixed;
--degrees: 115deg;
--colorStop-1: 50%;
--colorStop-2: calc(var(--colorStop-1) + 100px);
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
img {
width: 100%;
}
body {
font-family: "Noto Sans KR", sans-serif;
background-color: #fff;
color: #282828;
background-image: linear-gradient(
var(--degrees),
transparent var(--colorStop-1),
#fe4d3e var(--colorStop-1) var(--colorStop-2),
#fa7246 var(--colorStop-2)
),
radial-gradient(
circle at 20% 70%,
rgb(239 208 234 / 0.9),
rgb(234 201 242 / 0.6),
rgb(231 238 197 / 0.6),
rgb(205 240 219 / 0.6),
rgb(231 237 245 / 0.6)
);
background-attachment: var(--attachment);
min-height: 100vh;
overflow: hidden;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
background-image: linear-gradient(
115deg,
rgba(50 0 0 / 0.15) var(--colorStop-1),
rgb(53 53 53) var(--colorStop-1)
);
background-attachment: var(--attachment);
margin-top: 10px;
}
.header h1 {
font-size: 2rem;
padding-left: 1rem;
}
.header p {
font-size: 1.5rem;
color: white;
padding-right: 13%;
}
.pokedex {
position: relative;
display: flex;
justify-content: flex-end;
}
.shiny-button {
position: absolute;
left: 20px;
top: 20px;
width: 5rem;
filter: drop-shadow(5px 5px 0 rgba(130, 217, 211, 0.408));
cursor: pointer;
}
div:has(.pokemon-3Dmodel) {
display: flex;
justify-content: center;
align-items: center;
margin-inline: auto;
}
.pokemon-3Dmodel {
filter: drop-shadow(8px 8px 3px #39393951);
}
.pokemon-list {
width: clamp(360px, 100%, 520px);
height: calc(100vh - 56px);
display: flex;
overflow-y: scroll;
overflow-x: visible;
flex-direction: column;
gap: 15px;
padding: 20px 10px 20px 0;
margin-right: 20px;
border: 3px solid gold;
position: relative;
}
.pokemon-list::before {
content: "+";
position: absolute;
top: 0;
left: -1rem;
font-size: 3rem;
border: 3px solid blue;
line-height: 1em;
}
.pokemon {
display: flex;
justify-content: space-between;
align-items: center;
text-transform: capitalize;
padding: 0 10px 0 0;
color: black;
font-weight: 500;
font-size: 1.3rem;
border-radius: 100vw;
cursor: pointer;
}
.pokemon:hover,
.pokemon-active {
background-image: linear-gradient(115deg, #f04f17 45%, black 45%);
color: white;
}
.pokemon-active {
position: relative;
}
.pokemon-active .pokeball {
animation: rotate 1600ms infinite linear;
}
@keyframes rotate {
to {
rotate: 360deg;
}
}
.pokemon > div:first-of-type {
display: flex;
align-items: center;
}
.pokemon__sprite {
width: 60px;
scale: 1.2;
transform-origin: bottom;
margin-inline: 10px;
}
.pokemon__num {
display: flex;
}
.pokemon__num--field {
margin-left: 0.5rem;
}
.pokeball {
width: 25px;
height: 25px;
display: flex;
}
<main>
<div class="header">
<h1>Pokédex</h1>
<p>By Number</p>
</div>
<section class="pokedex">
<div>
<div class="pokemon-3Dmodel">
<img src="">
</div>
</div>
<ul class="pokemon-list">
</ul>
</section>
</main>