0
我正在爲作業創建啓動板,並努力找到一種方法來循環播放單擊的音頻片段,然後再次單擊時停止音頻。我有這個代碼,但它不會循環atm(我是Javascript的新手,所以它可能需要向我解釋)。使用Javascript進行循環音頻onclick
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Title</title>
<link rel="stylesheet" href="css/style.css">
<script> var one = new Audio(); var two = new Audio(); var three = new Audio(); var four = new Audio();
var five = new Audio(); var six = new Audio(); var seven = new Audio(); var eight = new Audio();
one.src = "files/audio/one.wav"; two.src = "files/audio/two.wav"; three.src = "files/audio/three.wav";
four.src = "files/audio/four.wav"; five.src = "files/audio/five.wav"; six.src = "files/audio/six.wav";
seven.src = "files/audio/seven.wav"; eight.src = "files/audio/eight.wav";
</script>
</head>
<div class="parent">
<div class="item" onmousedown="one.play()">Bass</div>
<div class="item" onmousedown="two.play()">Bass</div>
<div class="item" onmousedown="three.play()">Bass</div>
<div class="item" onmousedown="four.play()">Beat</div>
<div class="item" onmousedown="five.play()">Beat</div>
<div class="item" onmousedown="six.play()">Beat</div>
<div class="item" onmousedown="seven.play()">Drum</div>
<div class="item" onmousedown="eight.play()">Drum</div>
</div>