單擊暫停按鈕時如何使聲音淡出?單擊暫停按鈕時的fadeOut()聲音
<script>
var sounds = [
"sounds/royksopp.mp3",
"sounds/9thwonder.mp3",
"sounds/thisbeat.mp3",
"sounds/mosdef.mp3",
"sounds/bewater.mp3",
"sounds/boutdre.mp3",
"sounds/masterflash.mp3",
"sounds/2ep.mp3",
"sounds/drewestcoast.mp3",
"sounds/poetry.mp3",
"sounds/mfdoom.mp3",
"sounds/oizo.mp3",
];
function StartOrStop(audioFile) {
srcAudio = sounds[Math.floor(Math.random() * sounds.length)];
var audie = document.getElementById("myAudio");
audie.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
if (audie.paused == false) {
audie.pause();
} else {
audie.src = srcAudio;
audie.play();
}
}
</script>
然後,我把它叫做:
<audio id="myAudio"></audio>
<button id="idj-play-button" onclick="StartOrStop()" class="btn btn-lg"><i class="glyphicon glyphicon-play"></i>
</button>
<button id="idj-pause-button" onclick="StartOrStop()" class="btn btn-lg hide"><i class="glyphicon glyphicon-refresh"></i>
</button>
我需要改變我的if/else語句audie.pause()
什麼?我試過audie.animate({volume: 0}, 1000);
,但沒有奏效。
謝謝。
使用'.animate'您需要的音頻是一個jQuery元素:'$(audie).animate(...)' – davidchoo12
如果我使用'$(audie).animate({volume:0},500);'而不是'audie.pause();'它成功將音量降低到0,但是當我再次單擊播放按鈕時,沒有任何反應。 – Rui