Widget:Test: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
Linha 37: | Linha 37: | ||
justify-content: center; | justify-content: center; | ||
} | } | ||
.image-item { margin-bottom: 1em; } | .image-item { | ||
.image- | margin-bottom: 1em; | ||
text-align: center; | |||
} | |||
.image-item img { | |||
display: block; | |||
margin: 0 auto; | |||
} | |||
.variations-container { | .variations-container { | ||
Linha 79: | Linha 85: | ||
const imageList = { | const imageList = { | ||
'Charmander': { | 'Charmander': { | ||
imageUrl: 'https://example.com/charmander.png', | imageUrl: 'https://example.com/charmander.png', | ||
variations: [ | variations: [ | ||
{ | { | ||
Linha 98: | Linha 104: | ||
}, | }, | ||
'Bulbasaur': { | 'Bulbasaur': { | ||
imageUrl: 'https://example.com/bulbasaur.png' | imageUrl: 'https://example.com/bulbasaur.png' | ||
}, | }, | ||
'Squirtle': { | 'Squirtle': { | ||
imageUrl: 'https://example.com/squirtle.png' | imageUrl: 'https://example.com/squirtle.png' | ||
} | } | ||
}; | }; | ||
Linha 161: | Linha 157: | ||
<div class="image-item"> | <div class="image-item"> | ||
<img src="${imageInfo.imageUrl}" alt="${imageName}"> | <img src="${imageInfo.imageUrl}" alt="${imageName}"> | ||
</div> | </div> | ||
`; | `; |
Edição das 04h41min de 30 de agosto de 2024
<!DOCTYPE html> <html lang="pt-BR"> <head>
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Busca de Imagens por Nome</title> <style> .input-group { margin-bottom: 1em; position: relative; } .dropdown { border: 1px solid #ccc; display: none; position: absolute; background-color: #fff; z-index: 1000; max-height: 150px; overflow-y: auto; width: 100%; } .dropdown-item { padding: 8px; cursor: pointer; display: flex; align-items: center; } .dropdown-item img { width: 30px; height: 30px; margin-right: 10px; } .dropdown-item:hover { background-color: #f0f0f0; } .image-container { display: flex; flex-direction: column; align-items: center; justify-content: center; } .image-item { margin-bottom: 1em; text-align: center; } .image-item img { display: block; margin: 0 auto; } .variations-container { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 1em; }
.variation-item { width: 30%; box-sizing: border-box; margin: 10px; text-align: center; border: 1px solid #ccc; padding: 10px; }
.variation-item img { width: 100px; height: 100px; display: block; margin: 0 auto 10px; } </style>
</head> <body>
<form id="imageForm">
<input type="text" id="imageSearch" placeholder="Digite o nome da imagem" autocomplete="off">
</form>
<script> const imageList = { 'Charmander': { imageUrl: 'https://example.com/charmander.png', variations: [ { description: 'Charmander versão especial de evento.', obtain: { url: 'https://wiki.pokexgames.com/index.php/Charmander_Event', text: 'Evento especial Charmander' } }, { description: 'Charmander com habilidade rara.', obtain: { url: 'https://wiki.pokexgames.com/index.php/Charmander_Habilidade', text: 'Habilidade Rara de Charmander' } } ] }, 'Bulbasaur': { imageUrl: 'https://example.com/bulbasaur.png' }, 'Squirtle': { imageUrl: 'https://example.com/squirtle.png' } };
const imageSearch = document.getElementById('imageSearch'); const dropdown = document.getElementById('dropdown'); const imageContainer = document.getElementById('imageContainer');
imageSearch.addEventListener('input', function() { const searchValue = this.value.trim().toLowerCase(); dropdown.innerHTML = ;
if (searchValue) { Object.keys(imageList).forEach(imageName => { if (imageName.toLowerCase().includes(searchValue)) { const dropdownItem = document.createElement('div'); dropdownItem.classList.add('dropdown-item'); const imgElement = document.createElement('img'); imgElement.src = imageList[imageName].imageUrl; imgElement.alt = imageName; dropdownItem.appendChild(imgElement); dropdownItem.appendChild(document.createTextNode(imageName)); dropdownItem.addEventListener('click', function() { showImageInfo(imageName); dropdown.style.display = 'none'; }); dropdown.appendChild(dropdownItem); } });
dropdown.style.display = dropdown.childNodes.length ? 'block' : 'none'; } else { dropdown.style.display = 'none'; } });
document.addEventListener('click', function(event) { if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) { dropdown.style.display = 'none'; } });
function showImageInfo(imageName) { const imageInfo = imageList[imageName]; let imagesHtml = `
<img src="${imageInfo.imageUrl}" alt="${imageName}">
`;
if (imageInfo.variations) {
imagesHtml += '
';
imageInfo.variations.forEach(variation => { imagesHtml += `
<img src="https://via.placeholder.com/100" alt="Variation Image">
Descrição: ${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
`; });imagesHtml += '
';
}
imageContainer.innerHTML = imagesHtml; imageContainer.classList.remove('hidden'); } </script>
</body> </html>