var audio = new Audio('click.mp3');
$("nav li").mouseover(function() {
audio.play();
}).mouseout(function() {
audio.pause();
});
这是我的代码,在悬停音频文件时播放很多次,我想知道要添加什么来让它在悬停时只播放一次不是很多次
答案 0 :(得分:1)
var audio = new Audio('click.mp3');
var hasBeenPlayed = false;
$("nav li").mouseover(function() {
if(!hasBeenPlayed) {
audio.play();
hasBeenPlayed = true;
}
}).mouseout(function() {
audio.pause();
hasBeenPlayed = false;
});