Skip to content

Instantly share code, notes, and snippets.

@SomeKay
Created August 4, 2015 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SomeKay/c8d21791c2ab34834aea to your computer and use it in GitHub Desktop.
Save SomeKay/c8d21791c2ab34834aea to your computer and use it in GitHub Desktop.
index.js belonging to main window
'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