【问题标题】:Audio Fade in and Fade Out with jQueryjQuery 音频淡入淡出
【发布时间】:2020-02-08 14:01:03
【问题描述】:

我正在尝试淡入和淡出,但我不知道我的代码出了什么问题。淡入工作,但淡出不工作。

代码下方:

        var mPlayer = document.getElementById("pad-c");
        $(mPlayer).prop("volume", 0.0);

        var isPlaying = false;

        function playAudio() { 
            mPlayer.play(); 
            isPlaying = true;
        } 

        function pauseAudio() { 
            mPlayer.pause();
            isPlaying = false;
        } 
        function playPauseC() {
          if (isPlaying == true) {
            $(mPlayer).animate({volume: 0.1}, 5000);
            pauseAudio();
          } else {
            $(mPlayer).animate({volume: 1.0}, 5000);
            playAudio();
          }
        }

【问题讨论】:

  • 请注意,堆栈溢出以英语作为通用语言工作
  • 生活学习!谢谢。

标签: javascript jquery html audio


【解决方案1】:

现在您在淡出的同时暂停音频。使用.animate() 上的complete 参数淡出完成后暂停音频。

function playPauseC(){
  if(isPlaying == true) {
    $(mPlayer).animate({volume: 0.1}, 5000, function() {
      pauseAudio();
    });
  } else {
    $(mPlayer).animate({volume: 1.0}, 5000);
    playAudio();
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多