0

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?

4

1 回答 1

0

尝试将preload="auto"属性添加到您的音频标签

于 2013-04-22T21:03:16.520 回答