admin管理员组文章数量:1323723
What is the best solution to play an audio file on mouse over via JavaScript? And stop it when the mouse leaves the link. jQuery is available.
<a href="/test.mp3" class="play">play</a>
What is the best solution to play an audio file on mouse over via JavaScript? And stop it when the mouse leaves the link. jQuery is available.
<a href="/test.mp3" class="play">play</a>
Share
Improve this question
edited Feb 22, 2013 at 21:52
powtac
asked Jun 10, 2010 at 11:23
powtacpowtac
41.1k28 gold badges118 silver badges172 bronze badges
4
-
3
As a member of humanity, I ask you to at least make this a
click
event. – Nick Craver Commented Jun 10, 2010 at 11:44 - As a fan of clear (HT) Markup Language I want to keep this link to a audio file. Adding just a little JS fancy... – powtac Commented Jun 10, 2010 at 11:54
- I think you missed my point, as a majority, users prefer not to have a sound startup when simply moving their mouse across the page, it should be a click, not a hover. Why do you think flash based ads with high volume are going away and ad/flash blockers usage is skyrocketing? A lot of the same reasoning applies here...just something you should consider. – Nick Craver Commented Jun 10, 2010 at 12:12
- @Nick: Its for an application which handles a lot of audio files and clicking is slower than hovering. It is for a backend administration tool and it is necessary to figure out very fast what file it is... – powtac Commented Jun 10, 2010 at 12:35
3 Answers
Reset to default 3<audio id="mysound" src="mysound.wav"></audio>
<button onmouseover="document.getElementById('mysound').play()" onmouseout="document.getElementById('mysound').pause()">Hover me!</button>
http://www.schillmania./projects/soundmanager2/
Provides HTML5 + legacy support
<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>
you can use the player that unomi suggested. works great
本文标签: javascriptPlay audio file on hover (and stop playing on mouseout)Stack Overflow
版权声明:本文标题:javascript - Play audio file on hover (and stop playing on mouseout) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742123585a2421836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论