I am simulating a "click" sound on every anchor tag and submit button click on the mobile website that I'm working on using the following code:
<audio id="mySoundClip" style=" display:none; visibility:hidden;">
<source src="@Url.Content("~/Content/audio/Click.ogg")" type="audio/ogg">
<source src="@Url.Content("~/Content/audio/Tock.mp3")" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script type="text/javascript">
var homeURL = '@Url.Action("Index", "Home")';
var audio = $("#mySoundClip")[0];
$("[href]").click(function () {
//alert("a clicked");
audio.play();
});
$(":submit").click(function () {
//alert("submit button clicked");
audio.play();
});
</script>
It's working as expected but there is a slight delay in when the sound file actually plays while clicking the anchor tags/submit buttons. Is there a way to play the sound file a little sooner than when it actually plays so it will seem like a native click?