Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                    <div class="container text-center mt-5"><button type="button" class="btn btn-success mb-5" id="generatePokemon">Get Pokemon</button></div>
    <!--     <div id="pokemonImage"></div> -->
    <div id="pokemonContainer" class="pokemon-container">
    	
    </div>
              
            
!

CSS

              
                body {
	background-image: url("https://i.imgur.com/l7VHiQD.png");
}


.pokemon-container {
	display: flex;
	flex-wrap: wrap;
	align-items: space-between;
	justify-content: center;
	margin: 0 auto;
	max-width: 1200px;
	-webkit-perspective: 100000;
	perspective: 100000;
}

.pokemon-container .pokemon-card.flipped {
	-webkit-transform: rotatey(-180deg);
	transform: rotatey(-180deg);
}

.pokemon-container .pokemon-card {
	width: 100%;
	height: 100%;
	transform-style: preserve-3d;
	transition: 0.5s;
	-webkit-transform-style: preserve-3d;
	-webkit-transition: 0.35s;
}

.pokemon-container .pokemon-card .face {
	width: 100%;
	height: 210px;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	z-index: 2;
}

.pokemon-container .pokemon-card .front {
	z-index: 1;
	cursor: pointer;
}

.pokemon-container .pokemon-card .back {
	-webkit-transform: rotatey(-180deg);
	transform: rotatey(-180deg);
	cursor: pointer;
}

.back img{
/* 	position:relative; */
/* 	top: -20px; */
	width:100%;
	height:240px;
	margin: 0;
	padding: 0;
}

.pokemon-card {
	text-align: center;
	margin-right: 15px;
	margin-bottom: 15px;
	border: 8px solid #f9ee75;
	border-radius: 15px;
	padding: 15px 15px 0 15px;
	max-width: 165px;
	-webkit-box-shadow: 0px 0px 7px 0.5px rgba(0, 0, 0, 0.8);
	-moz-box-shadow: 0px 0px 7px 0.5px rgba(0, 0, 0, 0.8);
	box-shadow: 0px 0px 7px 0.5px rgba(0, 0, 0, 0.8);
}

.imageContainer {
	border-radius: 50%;
	background-color: beige;
}

.pokemon-name {
	font-size: 0.8em;
	font-weight: bold;
	text-align: left;
}

.pokemon-hp {
	font-size: 0.7em;
	font-weight: bold;
	text-align: right;
	color: #c23b1f;
	/* 	margin-top: auto; */
}

.pokemon-type {
	font-size: 0.6em;
	font-weight: bold;
	text-align: left;
	margin-top: 20px;
	margin-bottom: 0;
}

.pokemon-id {
	font-size: 0.6em;
	font-weight: bold;
	text-align: right;
	color: darkgreen;
	margin-top: 20px;
	margin-bottom: 0;
}

.pokemon-type-id {
	margin-bottom: 0;
}

/* .row, .col-4, .col-6, .col-8 {
	border: solid black 2px;
} */

              
            
!

JS

              
                //stop codepen from exiting loop
window.CP.PenTimer.MAX_TIME_IN_LOOP_WO_EXIT = 6000;

const pokemonInfoUrl = `https://pokeapi.co/api/v2/pokemon/`;
const pokemonImageUrl = `https://pokeres.bastionbot.org/images/pokemon/`;
const pokemonSpeciesUrl = `https://pokeapi.co/api/v2/pokemon-species/`;

const generatePokemonBtn = document.getElementById("generatePokemon");
let pokemonContainer = document.getElementById("pokemonContainer");
const pokemonImage = document.getElementById("pokemonImage");
const numOfPokemon = 151; //807 total
const elementColors = {
	grass: ["#ffffff", "#b6dfa5", "#7cd57a"],
	fire: ["#ffffff", "#e29a67", "#d53636"],
	water: ["#ffffff", "#a5c7df", "#7aacd5"],
	bug: ["#ffffff", "#d1dfa5", "#c2d57a"],
	normal: ["#ffffff", "#dfcda5", "#d5bd7a"],
	poison: ["#ffffff", "#b4a5df", "#807ad5"],
	electric: ["#ffffff", "#f6fb9f", "#fbff56"],
	ground: ["#ffffff", "#bbad8c", "#b9976b"],
	fairy: ["#ffffff", "#daa5df", "#d07ad5"],
	fighting: ["#ffffff", "#e2d067", "#d56f36"],
	psychic: ["#ffffff", "#a567e2", "#8036d5"],
	rock: ["#ffffff", "#ebb04f", "#a36d2c"],
	ghost: ["#ffffff", "#ba95df", "#9965d2"],
	ice: ["#ffffff", "#d8f3fa", "#7cd7f9"],
	dragon: ["#ffffff", "#f9fa49", "#f4c925"],
	dark: ["#ffffff", "#6c6c6c", "#000000"],
	steel: ["#ffffff", "#e6e5e5", "#8c8b8b"],
	flying: ["#ffffff", "#f9f9f9", "#dedede"]
};

generatePokemonBtn.addEventListener("click", async () => {
	for (let i = 1; i <= numOfPokemon; ++i) await fetchPokemon(i);
});

const fetchPokemon = async id => {
	const res = await fetch(pokemonInfoUrl + id);
	const pokemon = await res.json();
	
	const res2 = await fetch(pokemonSpeciesUrl + id);
	const pokemonSpecies = await res2.json();
	makePokemonCard(pokemon, pokemonSpecies, id);
};

const makePokemonCard = (pokemon, species, id) => {
	const pokemonCard = document.createElement("div");
	pokemonCard.classList.add("pokemon-card");
	
	pokemonCard.addEventListener("click", function () {
		pokemonCard.classList.toggle("flipped");
		
		let frontCard = pokemonCard.getElementsByClassName("front");
		let backCard = pokemonCard.getElementsByClassName("back");
		(frontCard[0].style.display === "block") ? frontCard[0].style.display = "none" : frontCard[0].style.display = "block";
		(backCard[0].style.display === "block") ? backCard[0].style.display = "none" : backCard[0].style.display = "block";
		
	});
	
	pokemonCard.setAttribute("id", `cardNum${id}`);
	const pokemonType = pokemon.types[0].type.name;
	const flavorText = species
		.flavor_text_entries[1]
		.flavor_text.replace(/[^0-9éa-zA-Z_.,']/gi, ' ')
		.replace('POKéMON', 'Pokémon');

	const frontFaceInnerHTML = `
	<div class="face front" style="display:block">
    	<div class="row pokemon-name-hp">
			<div class="col-6 pokemon-name"><p>${
				pokemon.name[0].toUpperCase() + pokemon.name.slice(1)
			}</p></div>
			<div class="col-6 pokemon-hp"><p>${pokemon.stats[0].base_stat} HP</p></div>
		</div>
      	<div class="imageContainer">
    		<div>
				<img src="${pokemonImageUrl}${id}.png" style="width:120px"/>
			</div>
     	</div>
		<div class="row pokemon-type-id mb-0 pb-0">
			<div class="col-8 pl-3 pokemon-type">
				<p>Type: ${pokemonType[0].toUpperCase() + pokemonType.slice(1)}</p>
			</div>
			<div class="col-4 pr-3 pokemon-id">
     			<p>#${pokemon.id}</p>
			</div>
		</div>
	</div>
	<div class="face back row mx-auto" style="display:none">
		<div class="col-12 p-0">
			<h6>${flavorText}</h6>
		</div>
	</div>
    `;
	
	pokemonCard.innerHTML = frontFaceInnerHTML;
	changeCardColor(pokemonCard, pokemonType);
	pokemonContainer.appendChild(pokemonCard);
	
};

const changeCardColor = (card, type) => {
	switch (type) {
		case "grass":
			card.style.background = `radial-gradient(circle, ${elementColors.grass[0]} 0%, ${elementColors.grass[1]} 50%, ${elementColors.grass[2]} 100%)`;
			break;
		case "fire":
			card.style.background = `radial-gradient(circle, ${elementColors.fire[0]} 0%, ${elementColors.fire[1]} 50%, ${elementColors.fire[2]} 100%)`;
			break;
		case "water":
			card.style.background = `radial-gradient(circle, ${elementColors.water[0]} 0%, ${elementColors.water[1]} 50%, ${elementColors.water[2]} 100%)`;
			break;
		case "bug":
			card.style.background = `radial-gradient(circle, ${elementColors.bug[0]} 0%, ${elementColors.bug[1]} 50%, ${elementColors.bug[2]} 100%)`;
			break;
		case "normal":
			card.style.background = `radial-gradient(circle, ${elementColors.normal[0]} 0%, ${elementColors.normal[1]} 50%, ${elementColors.normal[2]} 100%)`;
			break;
		case "poison":
			card.style.background = `radial-gradient(circle, ${elementColors.poison[0]} 0%, ${elementColors.poison[1]} 50%, ${elementColors.poison[2]} 100%)`;
			break;
		case "electric":
			card.style.background = `radial-gradient(circle, ${elementColors.electric[0]} 0%, ${elementColors.electric[1]} 50%, ${elementColors.electric[2]} 100%)`;
			break;
		case "ground":
			card.style.background = `radial-gradient(circle, ${elementColors.ground[0]} 0%, ${elementColors.ground[1]} 50%, ${elementColors.ground[2]} 100%)`;
			break;
		case "fairy":
			card.style.background = `radial-gradient(circle, ${elementColors.fairy[0]} 0%, ${elementColors.fairy[1]} 50%, ${elementColors.fairy[2]} 100%)`;
			break;
		case "fighting":
			card.style.background = `radial-gradient(circle, ${elementColors.fighting[0]} 0%, ${elementColors.fighting[1]} 50%, ${elementColors.fighting[2]} 100%)`;
			break;
		case "psychic":
			card.style.background = `radial-gradient(circle, ${elementColors.psychic[0]} 0%, ${elementColors.psychic[1]} 50%, ${elementColors.psychic[2]} 100%)`;
			break;
		case "rock":
			card.style.background = `radial-gradient(circle, ${elementColors.rock[0]} 0%, ${elementColors.rock[1]} 50%, ${elementColors.rock[2]} 100%)`;
			break;
		case "ghost":
			card.style.background = `radial-gradient(circle, ${elementColors.ghost[0]} 0%, ${elementColors.ghost[1]} 50%, ${elementColors.ghost[2]} 100%)`;
			break;
		case "ice":
			card.style.background = `radial-gradient(circle, ${elementColors.ice[0]} 0%, ${elementColors.ice[1]} 50%, ${elementColors.ice[2]} 100%)`;
			break;
		case "dragon":
			card.style.background = `radial-gradient(circle, ${elementColors.dragon[0]} 0%, ${elementColors.dragon[1]} 50%, ${elementColors.dragon[2]} 100%)`;
			break;
		case "dark":
			card.style.background = `radial-gradient(circle, ${elementColors.dark[0]} 0%, ${elementColors.dark[1]} 50%, ${elementColors.dark[2]} 100%)`;
			break;
		case "steel":
			card.style.background = `radial-gradient(circle, ${elementColors.steel[0]} 0%, ${elementColors.steel[1]} 50%, ${elementColors.steel[2]} 100%)`;
			break;
		case "flying":
			card.style.background = `radial-gradient(circle, ${elementColors.flying[0]} 0%, ${elementColors.flying[1]} 50%, ${elementColors.flying[2]} 100%)`;
			break;
	}
};

              
            
!
999px

Console