javascript - MouseOver sound effect, a Better way than this -
i need sound on mouse on event, have way problem comes delay between mouse on , sound playing, due (i supposed) embed sound deal on code. know if there better way using js/jquery). not new html5 audio tag don't want implement in particular case.
an ajax call loads file, attached mouseover function named playsound()
function playsound() { $setsound = document.getelementbyid("soundwrapper").innerhtml="<embed id='sound' src='href' type=audio/mpeg hidden=false autostart=true volume=12>"; }
then mouseout event function named stopsound()
function stopsound() { $stopsound = document.getelementbyid("soundwrapper").innerhtml=""; }
nothing fancy work. problem said delay playing sound. there way play/stop embedded sound, not embed new 1 every time, or alike?.
thanks time , help. greetings.
if have ajax load audio tag (http://www.w3schools.com/tags/tag_audio.asp) desired place, can play using .play() method in js. becomes easy
$(yourmouseoverelement).on('mouseover', function(){$('#sound').play()});
then if want stop audio when mouse leaves:
$(yourmouseoverelement).on('mouseout', function(){$('#sound').stop()});
Comments
Post a Comment