【发布时间】:2016-12-05 04:45:20
【问题描述】:
因此,当您将鼠标悬停在 article 元素上时,此代码会播放音频剪辑。问题是当鼠标悬停在子元素上时它会停止。当鼠标悬停在通用 article 元素上并悬停在子元素上时,如何使 Stopsound 功能不运行?
编辑:基本上,当您交替悬停在哪个子元素上时,我不希望这两个函数运行。
function PlaySound(soundobj) {
var thissound = document.getElementById(soundobj);
thissound.play();
}
function StopSound(soundobj) {
var thissound = document.getElementById(soundobj);
thissound.pause();
thissound.currentTime = 0;
}
* {
margin: 0;
padding: 0;
}
article24 {
width: 50px;
height: 100px;
background-color: green;
}
#box24 {
width: 50px;
height: 50px;
background-color: blue;
}
#present24 {
width: 50px;
height: 50px;
background-color: red;
}
#bauble24 {
width: 10px;
height: 10px;
}
<audio id='mySound' src="http://www.freesound.org/data/previews/278/278903_3546642-lq.mp3"></audio>
<article id="article24" onmouseover="PlaySound('mySound')" onmouseout="StopSound('mySound')">
<div id="box24">
<h2></h2>
</div>
<div id="present24">
<a href="">
<div id="bauble24">
<p id="belle24">""</p>
</div>
</a>
</div>
</article>
【问题讨论】:
标签: javascript html