Javascript 如何停止其他声音直到一个声音结束(Js、HTML)

Javascript 如何停止其他声音直到一个声音结束(Js、HTML),javascript,html,mp3,Javascript,Html,Mp3,我需要在网站上包括一些声音文件,我录制了它们并使用了超级复杂的: <a href="seo.html" onmouseover="new Audio('sounds/seo.mp3').play()"> 当用户用鼠标滚动时播放它们。网站上共有四个链接 问题是,当我把鼠标移到其中一个上面时,它开始播放,然后如果我把鼠标移到另一个上面,它也会播放那个。如果我在链接上快速移动鼠标,我最终会变得乱七八糟,因为所有文件都在同一时间播放。我怎样才能阻止这一切 理想的情况是,在当前播放结束之

我需要在网站上包括一些声音文件,我录制了它们并使用了超级复杂的:

<a href="seo.html" onmouseover="new Audio('sounds/seo.mp3').play()">

当用户用鼠标滚动时播放它们。网站上共有四个链接

问题是,当我把鼠标移到其中一个上面时,它开始播放,然后如果我把鼠标移到另一个上面,它也会播放那个。如果我在链接上快速移动鼠标,我最终会变得乱七八糟,因为所有文件都在同一时间播放。我怎样才能阻止这一切

理想的情况是,在当前播放结束之前,其他人不能播放:)

下面的方法

注:未经测试;-)

HTML

<a href="seo.html" data-file="sounds/seo.mp3" class="onmousesound">a sound link</a> -
<a href="seo.html" data-file="sounds/seo.mp3" class="onmousesound">a sound link</a> -
<a href="seo.html" data-file="sounds/seo.mp3" class="onmousesound">a sound link</a> -
<a href="seo.html" data-file="sounds/seo.mp3" class="onmousesound">a sound link</a>
-
-
-
JS

var links = document.querySelectorAll('a.onmousesound');
var currentPlayedAudioInstance = null;

var onHoverPlaySound = function(element) {
 if (currentPlayedAudioInstance &&
     currentPlayedAudioInstance instanceof Audio) {

   // is playing ?
   // http://stackoverflow.com/questions/8029391/how-can-i-tell-if-an-html5-audio-element-is-playing-with-javascript
   if (!currentPlayedAudioInstance.paused && !currentPlayedAudioInstance.ended && 0 < currentPlayedAudioInstance.currentTime) {
     return false;
   }
 }

 var file = element.getAttribute('data-file');
 currentPlayedAudioInstance = new Audio(file);
 currentPlayedAudioInstance.play();
};

for (var i = 0; i < links.length; i++) {
 link.addEventListene('onmouseover', function() {
  onHoverPlaySound(links[i]);
 });
};
var links=document.querySelectorAll('a.onmousesound');
var currentPlayedAudioInstance=null;
var onHoverPlaySound=函数(元素){
如果(当前播放音频)&&
当前播放音频(音频的实例){
//在玩什么?
// http://stackoverflow.com/questions/8029391/how-can-i-tell-if-an-html5-audio-element-is-playing-with-javascript
如果(!currentPlayedAudioInstance.paused&&!currentPlayedAudioInstance.ended&&0
谢谢兄弟:)我做了一些调整和思考,但我有点成功了:)谢谢你的快速回复:)