Last active
April 30, 2021 19:04
-
-
Save m4rk3r/4e4deadeb760fe8d01b8553a8ac5fe36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let artists = { | |
'p': { | |
'name': 'Pheobe Bridgers', | |
'img': 'pheobe.png', | |
'audio': 'song.mp3' | |
}, | |
'q': { | |
'name': 'Queen', | |
'img': 'queen.png', | |
'audio': 'queen.mp3' | |
} | |
}; | |
let audio = document.createElement('audio'); | |
document.addEventListener('keyup', function (event) { | |
if (event.key in artists) { | |
let artist = artists[event.key]; | |
console.log(artist.name, artist.img, artist.audio); | |
img = document.createElement('img'); | |
img.src = artist.img; | |
document.body.append(img); | |
img.addEventListener('mouseover', () => { | |
audio.src = artist.audio; | |
audio.play(); | |
}); | |
img.addEventListener('mouseout', () => { | |
audio.pause(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment