播放上悬停的音频文件(播放和停止鼠标移开时) [英] Play audio file on hover (and stop playing on mouseout)

查看:798
本文介绍了播放上悬停的音频文件(播放和停止鼠标移开时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是通过JavaScript发挥鼠标的音频文件了最佳的解决方案?而当鼠标离开链接停止它。 jQuery是可用的。

 < A HREF =/请将test.mp3级=玩>玩< / A>


解决方案

 <音频ID =为mySoundSRC =mysound.wav>< /音频>
<按钮的onmouseover =的document.getElementById('为mySound')播放()的onmouseout =的document.getElementById('为mySound')暂停()。>将鼠标悬停ME<!/按钮>

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>

解决方案

<audio id="mysound" src="mysound.wav"></audio>
<button onmouseover="document.getElementById('mysound').play()" onmouseout="document.getElementById('mysound').pause()">Hover me!</button>

这篇关于播放上悬停的音频文件(播放和停止鼠标移开时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆