通過JavaScript在鼠標懸停播放音頻文件的最佳解決方案是什麼?當鼠標離開鏈接時停止它。 jQuery可用。懸停播放音頻文件(並停止播放鼠標)
<a href="/test.mp3" class="play">play</a>
通過JavaScript在鼠標懸停播放音頻文件的最佳解決方案是什麼?當鼠標離開鏈接時停止它。 jQuery可用。懸停播放音頻文件(並停止播放鼠標)
<a href="/test.mp3" class="play">play</a>
http://www.schillmania.com/projects/soundmanager2/
提供HTML5 +傳統支持
<script type="text/javascript">
(function($) {
$(function(){
$("a.play").each(function() {
$(this).mouseover(function(){
var mp3file = $(this).attr('href');
// asign this mp3file to the player and play it
}).mouseout(function() {
// tell the mp3 player to stop
});
});
});
})(jQuery);
</script>
您可以使用unomi建議玩家。偉大的作品
<audio id="mysound" src="mysound.wav"></audio>
<button onmouseover="document.getElementById('mysound').play()" onmouseout="document.getElementById('mysound').pause()">Hover me!</button>
作爲人類的一員,我請求你至少把它變成一個'click'事件。 – 2010-06-10 11:44:50
作爲清晰(HT)標記語言的粉絲,我希望將此鏈接保留爲音頻文件。添加一點JS的幻想...... – powtac 2010-06-10 11:54:02
我認爲你錯過了我的觀點,作爲大多數用戶,當簡單地在頁面上移動鼠標時,用戶不希望有一個良好的啓動,它*應該是一個點擊,而不是一個懸停。爲什麼你認爲高容量的基於Flash的廣告正在消失,並且廣告/閃光攔截器的使用率正在飛漲?許多相同的推理適用於這裏...只是你應該考慮的事情。 – 2010-06-10 12:12:55