因此,當您將鼠標懸停在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>
太棒了!最簡單的解決方案永遠是最好的。 – student42
這不是什麼大問題,但是如果你在剪輯播放結束後將鼠標懸停在哪個子元素上,它會重新開始。你知道一個類似的簡單修復嗎?如果你頭頂上沒有任何東西,不要爲此煩惱。 – student42