function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.currentTime = 0;
thissound.Play();
}
function StopSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Stop();
}
这是我播放音频文件的代码,
onmouseover="EvalSound('sound1')" onmouseout="StopSound('sound1')"
它目前正在悬停,但是当我回到它播放的图像时它不会回到开头,它会继续播放
最佳答案
这是一个simple example在鼠标悬停时播放音频文件并在鼠标移开时停止。
HTML:
<p onmouseover="PlaySound('mySound')"
onmouseout="StopSound('mySound')">Hover Over Me To Play</p>
<audio id='mySound' src='http://upload.wikimedia.org/wikipedia/commons/6/6f/Cello_Live_Performance_John_Michel_Tchaikovsky_Violin_Concerto_3rd_MVT_applaused_cut.ogg'/>
Javascript:
function PlaySound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.play();
}
function StopSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.pause();
thissound.currentTime = 0;
}
有关更多信息,请查看 MDN guide for embedding audio and video
关于Javascript 在悬停时播放声音。在悬停时停止并重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14926306/