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 do Pokémon" autocomplete="off">
</form>
<script>
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('keydown', function (event) {
if (dropdown.style.display === 'none' || !dropdown.childNodes.length) { return; // Sai da função se o dropdown estiver escondido ou vazio }
const allItems = dropdown.querySelectorAll('.dropdown-item'); let activeItem = document.querySelector('.dropdown-item.active');
if (event.key === 'ArrowDown') { allItems.forEach(item => item.classList.remove('active')); // Remove 'active'
if (activeItem) { const nextItem = activeItem.nextElementSibling || allItems[0]; nextItem.classList.add('active'); nextItem.scrollIntoView({ block: "nearest" }); } else { allItems[0].classList.add('active'); allItems[0].scrollIntoView({ block: "nearest" }); } event.preventDefault(); } else if (event.key === 'ArrowUp') { allItems.forEach(item => item.classList.remove('active')); // Remove 'active'
if (activeItem) { const previousItem = activeItem.previousElementSibling || allItems[allItems.length - 1]; previousItem.classList.add('active'); previousItem.scrollIntoView({ block: "nearest" }); } else { allItems[allItems.length - 1].classList.add('active'); allItems[allItems.length - 1].scrollIntoView({ block: "nearest" }); } event.preventDefault(); } else if (event.key === 'Enter') { if (activeItem) { activeItem.click(); } event.preventDefault(); }
});
// Adicionar eventos ao passar o mouse dropdown.addEventListener('mouseover', function (event) {
if (event.target.classList.contains('dropdown-item')) { const allItems = dropdown.querySelectorAll('.dropdown-item'); allItems.forEach(item => item.classList.remove('active')); // Remove 'active' event.target.classList.add('active'); // Adiciona 'active' ao item do mouse }
});
// Adicionar evento ao tirar o mouse do dropdown dropdown.addEventListener('mouseout', function () {
const allItems = dropdown.querySelectorAll('.dropdown-item'); allItems.forEach(item => item.classList.remove('active')); // Remove 'active'
});
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}">
`;
imageInfo.variations.forEach((variation, index) => {
imagesHtml += `
<img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;">
<img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;">
Nome: ${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
Cor Customizável: ${variation.customColor}
`;
});imagesHtml += `
`;
imageContainer.innerHTML = imagesHtml; imageContainer.classList.remove('hidden');
// Alternar imagens ao clicar no botão de troca 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', () => { const variationImage = button.previousElementSibling; // Obtém a imagem da variação
// Aplica o efeito de saída variationImage.classList.add('fade-out');
// Aguarda o término da animação antes de trocar a imagem setTimeout(() => { currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length; variationImage.src = variation.additionalImages[currentImageIndex].url; variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`;
// Remove o efeito de saída e aplica o efeito de entrada variationImage.classList.remove('fade-out'); variationImage.classList.add('fade-in');
// Remove o efeito de entrada após a transição setTimeout(() => { variationImage.classList.remove('fade-in'); }, 300); // Duração da animação CSS (0.3s) }, 300); // Sincroniza com a duração do efeito de saída });
});
}
</script>
</body> </html>