Widget:Test: mudanças entre as edições

De PokeXGames
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; }
         .input-group { margin-bottom: 1em; position: relative; }
         .dropdown {
         .dropdown {
             border: 1px solid #ccc;
             border: 1px solid #ccc;
Linha 15: Linha 15:
             max-height: 150px;
             max-height: 150px;
             overflow-y: auto;
             overflow-y: auto;
            width: 100%;
         }
         }
         .dropdown-item {
         .dropdown-item {
             padding: 8px;
             padding: 8px;
             cursor: pointer;
             cursor: pointer;
            display: flex;
            align-items: center;
        }
        .dropdown-item img {
            width: 30px;
            height: 30px;
            margin-right: 10px;
         }
         }
         .dropdown-item:hover {
         .dropdown-item:hover {
Linha 68: Linha 76:
                     if (imageName.toLowerCase().includes(searchValue)) {
                     if (imageName.toLowerCase().includes(searchValue)) {
                         const dropdownItem = document.createElement('div');
                         const dropdownItem = document.createElement('div');
                        dropdownItem.textContent = imageName;
                         dropdownItem.classList.add('dropdown-item');
                         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() {
                         dropdownItem.addEventListener('click', function() {
                             showImageInfo(imageName);
                             showImageInfo(imageName);

Edição das 01h50min 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-item { margin-bottom: 1em; }
       .image-info { margin-top: 0.5em; }
   </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', 
               description: 'Charmander, o Pokémon de fogo inicial.' 
           },
           'Bulbasaur': { 
               imageUrl: 'https://example.com/bulbasaur.png', 
               description: 'Bulbasaur, o Pokémon de grama inicial.' 
           },
           'Squirtle': { 
               imageUrl: 'https://example.com/squirtle.png', 
               description: 'Squirtle, o Pokémon de água inicial.' 
           }
           // Adicione mais imagens conforme necessário
       };
       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];
           const imagesHtml = `
                   <img src="${imageInfo.imageUrl}" alt="${imageName}">
                       Nome da Imagem: ${imageName} 
Descrição: ${imageInfo.description}
URL: ${imageInfo.imageUrl}
           `;
           imageContainer.innerHTML = imagesHtml;
           imageContainer.classList.remove('hidden');
       }
   </script>

</body> </html>