我是javascript / jquery的新手,正在尝试运行以下代码:
function playSound(chosenColour) {
var sound = new Audio("sounds/" + chosenColour + ".mp3");
sound.play();
}
function nextInSequence() {
var randomNumber = Math.floor(Math.random() * 4);
var randomChosenColour = buttonColours[randomNumber];
gamePattern.push(randomChosenColour);
$("#" + randomChosenColour).animate({
opacity: 0
}, {
duration: 50,
start: function() {
playSound(randomChosenColour);
}
}).animate({
opacity: 1
}, 50);
}
The nextInSequence()
function is called via a keydown
event listener. For some reason when I press the alt, ctrl, shift or windows keys, the animate
part of the code runs but it doesn't playSound()
. Can someone please explain why?