Created
August 4, 2015 21:14
-
-
Save SomeKay/c8d21791c2ab34834aea to your computer and use it in GitHub Desktop.
index.js belonging to main window
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
'use strict'; | |
var soundButtons = document.querySelectorAll('.button-sound'); | |
for (var i = 0; i < soundButtons.length; i++) { | |
var soundButton = soundButtons[i]; | |
var soundName = soundButton.attributes['data-sound'].value; | |
prepareButton(soundButton, soundName); | |
} | |
function prepareButton(buttonEl, soundName) { | |
buttonEl.querySelector('span').style.backgroundImage = 'url("img/icons/' + soundName + '.png")'; | |
var audio = new Audio(__dirname + '/wav/' + soundName + '.wav'); | |
buttonEl.addEventListener('click', function () { | |
audio.currentTime = 0; | |
audio.play(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment