Below is a complete HTML code for a simple website that displays the first 100 Pokémon from the Pokédex. Each Pokémon is shown in a grid, and clicking on a Pokémon will open a modal or section with a basic 3D animation. For the 3D animations, I'll use the Three.js library (a popular JavaScript library for 3D graphics in the browser). Since actual 3D models for Pokémon aren't freely available for direct use, I'll create simple placeholders (e.g., a rotating 3D cube or sphere) for each Pokémon. You can later replace these with custom models if you obtain them.
Key Features:
- Pokémon Data: Fetched from the PokéAPI (a free API for Pokémon data).
- Display: A responsive grid showing the first 100 Pokémon with their names and images.
- 3D Animations: When you click a Pokémon, a 3D scene is rendered using Three.js. For now, it's a simple animated 3D object (e.g., a rotating cube) with the Pokémon's name overlaid. In a real-world scenario, you'd integrate actual 3D models (e.g., from GLTF files).
- Interactivity: Uses JavaScript for fetching data, rendering the grid, and handling 3D animations.
- Responsive Design: The grid adapts to different screen sizes.
Prerequisites:
- Internet Access: The code relies on external CDNs for Three.js and PokéAPI.
- Customization: You'll need to host this on a web server or run it locally with a server (e.g., via Live Server in VS Code) because PokéAPI requests might not work with file:// protocols due to CORS.
- Enhancements: If you want more advanced 3D models, you could use tools like Blender to create them and load them via Three.js (e.g., using GLTFLoader).
Here's the full HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pokédex: First 100 Pokémon with 3D Animations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
header {
background-color: #ffcb05; /* Pokémon yellow */
color: #3b4cca; /* Pokémon blue */
text-align: center;
padding: 20px;
font-size: 24px;
}
.pokemon-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
padding: 20px;
}
.pokemon-card {
background-color: white;
border: 1px solid #ddd;
border-radius: 8px;
text-align: center;
padding: 10px;
cursor: pointer;
transition: transform 0.3s;
}
.pokemon-card:hover {
transform: scale(1.05);
}
.pokemon-card img {
width: 100%;
height: auto;
border-radius: 4px;
}
.modal {
display: none; /* Hidden by default */
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background-color: white;
padding: 20px;
border-radius: 8px;
max-width: 80%;
max-height: 80%;
position: relative;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
font-size: 20px;
}
#threejs-container {
width: 100%;
height: 400px; /* Height for 3D canvas */
}
</style>
</head>
<body>
<header>
<h1>Pokédex: First 100 Pokémon</h1>
<p>Click on a Pokémon to see its 3D animation!</p>
</header>
<div id="pokemon-grid" class="pokemon-grid"></div>
<!-- Modal for 3D Animation -->
<div id="modal" class="modal">
<div class="modal-content">
<span class="close-btn" onclick="closeModal()">×</span>
<h2 id="modal-title"></h2>
<div id="threejs-container"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> <!-- Three.js CDN -->
<script>
// Function to fetch and display the first 100 Pokémon
async function fetchPokemon() {
const grid = document.getElementById('pokemon-grid');
for (let i = 1; i <= 100; i++) { // First 100 Pokémon (IDs 1-100)
try {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${i}`);
const data = await response.json();
const card = document.createElement('div');
card.className = 'pokemon-card';
card.innerHTML = `
<img src="${data.sprites.front_default}" alt="${data.name}">
<h3>${data.name.toUpperCase()}</h3>
`;
card.onclick = () => openModal(data.name, data.sprites.front_default);
grid.appendChild(card);
} catch (error) {
console.error(`Error fetching Pokémon ${i}:`, error);
}
}
}
// Function to open the modal and initialize 3D scene
function openModal(pokemonName, imageUrl) {
document.getElementById('modal').style.display = 'flex';
document.getElementById('modal-title').innerText = pokemonName.toUpperCase();
// Set up Three.js scene
const container = document.getElementById('threejs-container');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(container.clientWidth, container.clientHeight);
container.innerHTML = ''; // Clear previous content
container.appendChild(renderer.domElement);
// Add a simple 3D object (e.g., a rotating cube as a placeholder)
const geometry = new THREE.BoxGeometry(); // Cube geometry
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true }); // Green wireframe for visibility
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5; // Position the camera
// Animation loop
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01; // Rotate on X-axis
cube.rotation.y += 0.01; // Rotate on Y-axis
renderer.render(scene, camera);
}
animate();
}
// Function to close the modal
function closeModal() {
document.getElementById('modal').style.display = 'none';
// Clean up Three.js renderer if needed
const container = document.getElementById('threejs-container');
if (container.firstChild) {
container.removeChild(container.firstChild); // Remove the canvas
}
}
// Load Pokémon on page load
window.onload = fetchPokemon;
</script>
</body>
</html>
How It Works:
- Fetching Data: The JavaScript code uses
fetch to get data for each Pokémon (from ID 1 to 100) from the PokéAPI. It extracts the name and front-facing image sprite.
- Grid Display: The Pokémon are displayed in a responsive grid. Each card shows the Pokémon's image and name. Clicking a card triggers the
openModal function.
- 3D Animation:
- Modal Interaction: The modal can be closed by clicking the 'X' button.
- Styling: Basic CSS is included for a clean layout. You can customize it further.
Limitations and Improvements:
- Placeholder 3D Animation: The current animation is just a rotating cube. To make it more Pokémon-specific:
- Download or create 3D models (e.g., from sites like Sketchfab or by modeling in Blender) and load them via Three.js.
- Enhance the scene by adding lights, textures, or even the Pokémon's image as a texture on the cube.
- Performance: Fetching 100 API calls at once might be slow. Consider batching requests or using a local cache.
- Error Handling: Basic error logging is included; you might want to add user-friendly messages.
- Mobile Support: The grid is responsive, but 3D interactions might need touch adjustments (e.g., add orbit controls from Three.js).
- Legal Note: Pokémon is a trademark of Nintendo. This is for educational purposes; ensure you comply with their IP guidelines for any public deployment.
If you'd like me to add more features (e.g., search functionality, better 3D models, or animations), let me know!