html5 audio player - jquery toggle click play/pause?

前端 未结 15 2414
南笙
南笙 2020-11-28 06:24

i wonder what i\'m doing wrong?

    $(\'.player_audio\').click(function() {
    if ($(\'.player_audio\').paused == false) {
        $(\'.player_audio\').paus         


        
15条回答
  •  借酒劲吻你
    2020-11-28 06:32

    I'm not sure why, but I needed to use the old skool document.getElementById();

    
    play sound
    

    and the JS:

    $(document).ready(function() {
      var playing = false;
    
      $('a#button').click(function() {
          $(this).toggleClass("down");
    
          if (playing == false) {
              document.getElementById('player').play();
              playing = true;
              $(this).text("stop sound");
    
          } else {
            document.getElementById('player').pause();
            playing = false;
            $(this).text("restart sound");
          }
    
      });
    });
    

    Check out an example: http://jsfiddle.net/HY9ns/1/

提交回复
热议问题