Skip to content

Instantly share code, notes, and snippets.

@thecooldaniel
Created November 8, 2012 22:55
Show Gist options
  • Save thecooldaniel/4042413 to your computer and use it in GitHub Desktop.
Save thecooldaniel/4042413 to your computer and use it in GitHub Desktop.
ongoing html5 audio js implamention
function domCreate(obj) {
var ref = document.createElement(obj.tag);
if(obj.att){for (var i = obj.att.length - 1; i >= 0; i--) {
$(ref).attr(obj.att[i].name, obj.att[i].value);
};}
if(obj.children){
for (var i = obj.children.length - 1; i >= 0; i--) {
ref.appendChild(domCreate(obj.children[i]));
};
}
return ref;
}
function createSound(event, selector, src){
var obj = {
'tag':'audio',
'children': [
{
'tag':'source',
'att': [
{'name':'src','value':src+'.ogg'},
{'name':'type','value':'audio/ogg'}
]
},
{
'tag':'source',
'att': [
{'name':'src','value':src+'.mp3'},
{'name':'type','value':'audio/mpeg'}
]
}
]
}
$(selector).each(function(index){
var audio = domCreate(obj);
$(this).bind(event, function(){
audio.play();
})
})
}
createSound('mouseenter', '#a li, #footer ul li a', '/audio/beep');
createSound('mouseenter', 'div#brandSlider ul li div a', '/audio/beep2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment