我对javascript相当陌生,并试图在mousemove上播放随机选择的声音。我无法上班,希望能得到帮助。我正在使用 howler.min.js 来控制声音,因此在播放下一个声音之前不要等待声音播放结束。这是代码:
var soundObjects = [];
var lastSoundTime = Date.now();
c.addEventListener("mousemove",function(evt){
var mx = evt.clientX - this.offsetLeft;
var my = evt.clientY - this.offsetTop;
//console.log("clicked at x:" + mx + ", y:" + my);
//
circles.push(makeMovingCircle(mx, my));
var now = Date.now();
var elapsed = now - lastSoundTime;
console.log(elapsed);
if (elapsed < 250) {
return
}
lastSoundTime = now;
new Howl({
var sounds = ['splash.mp3',
'splash.ogg',
'splash1.mp3',
'splash1.ogg',
'splash2.mp3',
'splash2.ogg',
'splash3.mp3',
'splash3.ogg',
'splash4.mp3',
'splash4.ogg',
'splash5.mp3',
'splash5.ogg'];
var soundFile = sounds[Math.floor(Math.random()*sounds.length)];
}
}).play();