-1

I need another set of eyes on this.

I have various "hover sounds" that work fine using HTML5. Now I'm trying to add "click to play" image, using jQuery to play the HTML Audio. Here is my code:

    $(".audio_photography").click(function(){
            photography_audio.play();
        },
        function(){
            photography_audio.pause();
        });

and HTML

        <span class="audio_photography">
            <audio id="photography_audio">
                <source src="audio/cherish-the-day.mp3" type="audio/mpeg"></source>
                <source src="audio/cherish-the-day.ogg" type="audio/ogg"></source>
            </audio>
        </span>

Nothing happens when clicked. I double checked the path to my mp3/ogg, and it's correct.

Any ideas on what I'm doing wrong?

Just in case, here is the whole jQuery script:

 <script type="text/javascript">
    $(document).ready(function(){
        $(".main-navigation li").hover(function(){
            main_navigation_audio.play();
        },
        function(){
            main_navigation_audio.load();
        });
        $("#primary a, #secondary a, footer a").hover(function(){
            link_audio.play();
        },
        function(){
            link_audio.load();
        });
        $(".site-title a").hover(function(){
            header_audio.play();
        },
        function(){
            header_audio.load();
        });
        $("input, textarea, .site-header").hover(function(){
            input_textarea_audio.play();
        },
        function(){
            input_textarea_audio.load();
        });
        $(".audio_photography").click(function(){
            photography_audio.play();
        },
        function(){
            photography_audio.pause();
        });
    });
</script>

Thanks.

4

1 回答 1

0

这是我现在使用的脚本,它似乎可以工作。

        $('.audio_photography').click(function(){
              if(photography_audio.paused){
                photography_audio.play();
               } else {
                 photography_audio.pause();
               }
        });
于 2013-04-21T15:39:44.383 回答