Widget:Test
Ir para navegação
Ir para pesquisar
<!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>
</head> <body>
<form id="imageForm">
<input type="text" id="imageSearch" placeholder="Digite o nome da imagem" autocomplete="off">
</form>
<script>
// Elementos do DOM const imageSearch = document.getElementById('imageSearch'); const dropdown = document.getElementById('dropdown'); const imageContainer = document.getElementById('imageContainer');
// Filtro de busca 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');
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'; } });
// Exibir informações da imagem
function showImageInfo(imageName) {
const imageInfo = imageList[imageName]; let imagesHtml = `
<img src="${imageInfo.imageUrl}" alt="${imageName}" class="main-image">
`;
imageInfo.variations.forEach((variation, index) => { imagesHtml += `
<img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}"> <button class="swap-button" data-variation-index="${index}">Trocar</button>
<img src="${variation.descriptionIMG}" alt="Description Image" class="description-image">
${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
`; });imagesHtml += '
';
imageContainer.innerHTML = imagesHtml; imageContainer.classList.remove('hidden');
// Adicionar funcionalidade ao botão "Trocar" const swapButtons = document.querySelectorAll('.swap-button'); swapButtons.forEach(button => { const index = button.getAttribute('data-variation-index'); const variation = imageInfo.variations[index]; let currentImageIndex = 0;
button.addEventListener('click', () => { currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length; const variationImage = button.previousElementSibling; // Atualizar a imagem da variação variationImage.src = variation.additionalImages[currentImageIndex].url; }); });
}
</script>
</body> </html>