6 392
edições
Sem resumo de edição |
Sem resumo de edição |
||
Linha 55: | Linha 55: | ||
} | } | ||
}); | }); | ||
document.addEventListener('keydown', function (event) { | document.addEventListener('keydown', function (event) { | ||
Linha 67: | Linha 65: | ||
if (event.key === 'ArrowDown') { | if (event.key === 'ArrowDown') { | ||
allItems.forEach(item => item.classList.remove('active')); // Remove 'active' | |||
allItems.forEach(item => item.classList.remove('active')); // Remove | |||
if (activeItem) { | if (activeItem) { | ||
Linha 80: | Linha 77: | ||
event.preventDefault(); | event.preventDefault(); | ||
} else if (event.key === 'ArrowUp') { | } else if (event.key === 'ArrowUp') { | ||
allItems.forEach(item => item.classList.remove('active')); // Remove 'active' | |||
allItems.forEach(item => item.classList.remove('active')); // Remove | |||
if (activeItem) { | if (activeItem) { | ||
Linha 100: | Linha 96: | ||
}); | }); | ||
// Adicionar eventos ao passar o mouse | |||
dropdown.addEventListener('mouseover', function (event) { | dropdown.addEventListener('mouseover', function (event) { | ||
if (event.target.classList.contains('dropdown-item')) { | if (event.target.classList.contains('dropdown-item')) { | ||
const allItems = dropdown.querySelectorAll('.dropdown-item'); | const allItems = dropdown.querySelectorAll('.dropdown-item'); | ||
allItems.forEach(item => item.classList.remove('active')); // Remove | allItems.forEach(item => item.classList.remove('active')); // Remove 'active' | ||
event.target.classList.add('active'); // Adiciona 'active' ao item do mouse | event.target.classList.add('active'); // Adiciona 'active' ao item do mouse | ||
} | } | ||
}); | }); | ||
dropdown.addEventListener('mouseout', function ( | // 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) { | document.addEventListener('click', function(event) { | ||
if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) { | if (!imageSearch.contains(event.target) && !dropdown.contains(event.target)) { |