Widget:Test2: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
Linha 6: | Linha 6: | ||
<title>Busca de Imagens por Nome</title> | <title>Busca de Imagens por Nome</title> | ||
<style> | <style> | ||
.input-group { margin-bottom: 1em; position: relative; } | |||
.dropdown { | |||
.input-group { | |||
border: 1px solid #ccc; | border: 1px solid #ccc; | ||
display: none; | |||
position: absolute; | position: absolute; | ||
background-color: | background-color: #fff; | ||
z-index: 1000; | z-index: 1000; | ||
max-height: | max-height: 150px; | ||
overflow-y: auto; | overflow-y: auto; | ||
width: 100%; | |||
} | } | ||
.dropdown-item { | .dropdown-item { | ||
padding: | padding: 8px; | ||
cursor: pointer; | cursor: pointer; | ||
display: flex; | display: flex; | ||
align-items: center; | align-items: center; | ||
} | } | ||
.dropdown-item img { | |||
margin-right: 10px; | |||
} | |||
.dropdown-item:hover { | .dropdown-item:hover { | ||
background-color: #f0f0f0; | background-color: #f0f0f0; | ||
} | } | ||
.image-container { | .image-container { | ||
display: flex; | display: flex; | ||
flex- | flex-direction: column; | ||
align-items: center; | |||
justify-content: center; | |||
} | |||
.image-item { | |||
margin-bottom: 1em; | |||
text-align: center; | |||
} | } | ||
.image-item img { | .image-item img { | ||
display: block; | |||
margin: 0 auto; | |||
} | } | ||
Linha 74: | Linha 47: | ||
display: flex; | display: flex; | ||
flex-wrap: wrap; | flex-wrap: wrap; | ||
justify-content: center; | |||
margin-top: 1em; | |||
} | } | ||
.variation-item { | .variation-item { | ||
width: 35%; | |||
box-sizing: border-box; | |||
margin: 5px; | |||
text-align: center; | text-align: center; | ||
border: 1px solid ; | |||
padding: 10px; | |||
} | } | ||
.variation- | .variation-item img { | ||
display: block; | |||
margin: 0 auto 10px; | |||
} | } | ||
.swap-button { | .swap-button { | ||
margin-top: 10px; | |||
cursor: pointer; | cursor: pointer; | ||
width: 15px; | |||
height: 15px; | |||
background: url('https://wiki.pokexgames.com/images/f/fb/SwapButtonAddons.png') no-repeat center; | |||
background-size: contain; | |||
display: block; | |||
margin: 0 auto; | margin: 0 auto; | ||
} | } | ||
</style> | </style> | ||
Linha 115: | Linha 90: | ||
<script> | <script> | ||
// | // Função para gerar o link da imagem da Wiki | ||
function generateWikiImageUrl(imageName) { | |||
return `https://wiki.pokexgames.com/index.php/Special:FilePath/${imageName}.png`; | |||
} | |||
// Lista de imagens e variações | |||
const imageList = { | const imageList = { | ||
Squirtle: { | Squirtle: { | ||
imageUrl: | imageUrl: generateWikiImageUrl('007-Squirtle'), // URL dinâmica da imagem | ||
variations: [ | variations: [ | ||
{ | { | ||
description: "Squirtle usando óculos", | description: "Squirtle usando óculos", | ||
descriptionIMG: | descriptionIMG: generateWikiImageUrl('Squirtle_Glasses'), // URL da variação | ||
additionalImages: [ | additionalImages: [ | ||
{ url: | { url: generateWikiImageUrl('squirtle1'), width: 100 }, | ||
{ url: | { url: generateWikiImageUrl('squirtle2'), width: 120 } | ||
], | ], | ||
obtain: { url: "https://example.com/obter-squirtle", text: "Como obter" } | obtain: { url: "https://example.com/obter-squirtle", text: "Como obter" } | ||
Linha 132: | Linha 112: | ||
}, | }, | ||
Charmander: { | Charmander: { | ||
imageUrl: | imageUrl: generateWikiImageUrl('004-Charmander'), // URL dinâmica da imagem | ||
variations: [ | variations: [ | ||
{ | { | ||
description: "Charmander brilhante", | description: "Charmander brilhante", | ||
descriptionIMG: | descriptionIMG: generateWikiImageUrl('charmander-shiny'), // URL da variação | ||
additionalImages: [ | additionalImages: [ | ||
{ url: | { url: generateWikiImageUrl('charmander1'), width: 100 }, | ||
{ url: | { url: generateWikiImageUrl('charmander2'), width: 120 } | ||
], | ], | ||
obtain: { url: "https://example.com/obter-charmander", text: "Como obter" } | obtain: { url: "https://example.com/obter-charmander", text: "Como obter" } | ||
Linha 200: | Linha 180: | ||
imagesHtml += ` | imagesHtml += ` | ||
<div class="variation-item"> | <div class="variation-item"> | ||
<img src="${variation.additionalImages[0].url}" alt="Variation Image" class="variation-image" data-variation-index="${index}" style="width: ${variation.additionalImages[0].width}px;"> | |||
<div class="swap-button" data-variation-index="${index}"></div><br> | |||
<div class="image-info"> | <div class="image-info"> | ||
<img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> | <img src="${variation.descriptionIMG}" alt="Description Image" style="margin-right: 5px; display: inline-block;"> <!-- Exibe a imagem antes da descrição --> | ||
<br>${variation.description}<br> | <br> ${variation.description} <br> <!-- Descrição após a imagem --> | ||
<b>Como Obter</b>: <a href="${variation.obtain.url}" target="_blank | <b>Como Obter</b>: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a> | ||
</div> | </div> | ||
</div> | </div> | ||
Linha 216: | Linha 196: | ||
imageContainer.classList.remove('hidden'); | imageContainer.classList.remove('hidden'); | ||
// Alternar imagens ao clicar no botão de troca | |||
const swapButtons = document.querySelectorAll('.swap-button'); | const swapButtons = document.querySelectorAll('.swap-button'); | ||
Linha 225: | Linha 206: | ||
button.addEventListener('click', () => { | button.addEventListener('click', () => { | ||
currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length; | currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length; | ||
const variationImage = button.previousElementSibling; | const variationImage = button.previousElementSibling; // Atualiza a imagem da variação | ||
variationImage.src = variation.additionalImages[currentImageIndex].url; | variationImage.src = variation.additionalImages[currentImageIndex].url; | ||
variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`; | |||
}); | }); | ||
}); | }); |
Edição das 04h30min de 23 de dezembro 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 { 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: 35%; box-sizing: border-box; margin: 5px; text-align: center; border: 1px solid ; padding: 10px; }
.variation-item img { display: block; margin: 0 auto 10px; }
.swap-button { margin-top: 10px; cursor: pointer; width: 15px; height: 15px; background: url('https://wiki.pokexgames.com/images/f/fb/SwapButtonAddons.png') no-repeat center; background-size: contain; display: block; margin: 0 auto; } </style>
</head> <body>
<form id="imageForm">
<input type="text" id="imageSearch" placeholder="Digite o nome da imagem" autocomplete="off">
</form>
<script> // Função para gerar o link da imagem da Wiki function generateWikiImageUrl(imageName) { return `https://wiki.pokexgames.com/index.php/Special:FilePath/${imageName}.png`; }
// Lista de imagens e variações const imageList = { Squirtle: { imageUrl: generateWikiImageUrl('007-Squirtle'), // URL dinâmica da imagem variations: [ { description: "Squirtle usando óculos", descriptionIMG: generateWikiImageUrl('Squirtle_Glasses'), // URL da variação additionalImages: [ { url: generateWikiImageUrl('squirtle1'), width: 100 }, { url: generateWikiImageUrl('squirtle2'), width: 120 } ], obtain: { url: "https://example.com/obter-squirtle", text: "Como obter" } } ] }, Charmander: { imageUrl: generateWikiImageUrl('004-Charmander'), // URL dinâmica da imagem variations: [ { description: "Charmander brilhante", descriptionIMG: generateWikiImageUrl('charmander-shiny'), // URL da variação additionalImages: [ { url: generateWikiImageUrl('charmander1'), width: 100 }, { url: generateWikiImageUrl('charmander2'), width: 120 } ], obtain: { url: "https://example.com/obter-charmander", text: "Como obter" } } ] } };
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}">
`;
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;">
${variation.description}
Como Obter: <a href="${variation.obtain.url}" target="_blank">${variation.obtain.text}</a>
`; });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', () => { currentImageIndex = (currentImageIndex + 1) % variation.additionalImages.length; const variationImage = button.previousElementSibling; // Atualiza a imagem da variação variationImage.src = variation.additionalImages[currentImageIndex].url; variationImage.style.width = `${variation.additionalImages[currentImageIndex].width}px`; }); }); } </script>
</body> </html>