Created
November 8, 2012 22:55
-
-
Save thecooldaniel/4042413 to your computer and use it in GitHub Desktop.
ongoing html5 audio js implamention
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
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