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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -