jquery - click sound on <a> tag before it moves to another page -
i want give click sound tags on page before moves page.
i play click sound using tag.. doesn't work because page moves linked page before hear sound.
my code play sound follows:
<audio id="audio" hidden> <source src="./sound/sound.mp3" type="audio/mpeg"> </audio> $('#menu li a').click(function(e) { e.preventdefault(); // if utilize this, doesn't goes page. can here sound. want play sound , link both. var sound = $("#audio"); sound.get(0).play(); });
any tip appreciated. thanks.
here need... play sound , 1 time sound finishes playing, goes target location...
html
<audio id="audio" hidden> <source src="./sound/sound.mp3" type="audio/mpeg"> </audio> <div id="menu"> <li> <a href="http://www.google.com">click play...</a> </li> </div>
jquery
var target; function checkaudio() { if($("#audio")[0].paused) { window.location.href = target; } else { settimeout(checkaudio, 1000); } } $('#menu li a').click(function(e) { e.preventdefault(); target = $(this).attr('href'); console.log("let's play"); var sound = $("#audio"); sound.get(0).play(); settimeout(checkaudio, 1000); });
the code checks state of sound each second, can alter value of timeout check less frequently.
jquery html5 audio
No comments:
Post a Comment