-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (45 loc) · 1.94 KB
/
index.js
File metadata and controls
50 lines (45 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Crear un nuevo elemento de audio para el efecto de sonido
function playSound(soundFile) {
var audioPlayer = document.getElementById('audio-player');
audioPlayer.src = soundFile;
audioPlayer.play();
}
window.addEventListener('load', function() {
setTimeout(function() {
document.getElementById('intro').style.display = 'none';
}, 2000);
});
// Agregar el evento de mouseover a cada enlace del menú
const menuLinks = document.querySelectorAll('.menu a, .menu button, .menu li');
menuLinks.forEach(link => {
link.addEventListener('mouseover', function() {
hoverSound.currentTime = 0; // Reiniciar el sonido
hoverSound.play(); // Reproducir el sonido al pasar el ratón
});
});
const menuItems = document.querySelectorAll('.menu a, .menu button, .menu li');
let currentIndex = 0;
function updateActive() {
menuItems.forEach((item, index) => {
item.classList.toggle('active', index === currentIndex);
});
menuItems[currentIndex].focus(); // Focalizar el elemento activo
hoverSound.currentTime = 0; // Reiniciar el sonido
hoverSound.play(); // Reproducir el sonido al cambiar de elemento
}
document.querySelector('.menu').addEventListener('keydown', (event) => {
if (event.key === 'ArrowDown') {
currentIndex = (currentIndex + 1) % menuItems.length; // Mover hacia abajo
updateActive();
event.preventDefault(); // Prevenir el desplazamiento de la página
} else if (event.key === 'ArrowUp') {
currentIndex = (currentIndex - 1 + menuItems.length) % menuItems.length; // Mover hacia arriba
updateActive();
event.preventDefault(); // Prevenir el desplazamiento de la página
} else if (event.key === 'Enter') {
menuItems[currentIndex].click(); // Simular un clic en el elemento activo
}
});
// Focalizar el menú al cargar la página
document.querySelector('.menu').focus();
updateActive(); // Inicializa el estado activo