Jquery 鼠标上方的音频
它部分工作,但我如何让以下内容与多个音频文件一起工作:Jquery 鼠标上方的音频,jquery,html,javascript,Jquery,Html,Javascript,它部分工作,但我如何让以下内容与多个音频文件一起工作: <!DOCTYPE HTML> <html> <body> <script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(functio
<!DOCTYPE HTML>
<html>
<body>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
var birdhover = $('.birds');
var birdaudio = birdhover.find('audio')[0];
birdhover.hover(function(){
birdaudio.play();
}, function(){
birdaudio.stop();
});
});
</script>
<div class="birds" style="width:30px;height:30px;background-image:url(image1.gif');cursor:pointer;">
<audio src="sound1.ogg" preload="auto"></audio>
</div>
<div class="birds" style="width:30px;height:30px;background-image:url('/home/imran/Desktop/images/vowel_short_2.gif');cursor:pointer;">
(image2.gif');cursor:pointer;">
<audio src="sound2.ogg" preload="auto"></audio>
</div>
</body>
</html>
$(函数(){
var birdhover=$('.birds');
var birdaudio=birdhover.find('audio')[0];
hover(函数(){
比尔达乌迪奥;
},函数(){
停止();
});
});
(image2.gif');光标:指针;">
两个图像播放相同的声音。针对多个声音文件更新 这是我以前用过的: 用法:
$("#sound").sound({swf: url});
$("#sound").load(url);
$("#sound").play();
$("#sound").pause();
$("#sound").stop();
$("#sound").volume(0-100);
(摘自jQuery插件页面)
对于鼠标悬停:
$('#selector').mouseover(function() {
$("#sound").play('path/to/wav/or/mp3');
});
$('#second-selector').mouseover(function() {
$("#sound2").play('path/to/second/wav/or/mp3');
});
如果您不介意使用
HTML5
:
HTML
<div class="birds">
<audio src="/sounds/bird.mp3" preload="auto"></audio>
</div>
我刚刚尝试了这个方法,但它只是产生了一个空白屏幕?我应该在音频标签之间放置一个图像吗?我已经更新了原始问题,向您展示了我目前拥有的内容。您好,成功了,我没有意识到您在使用jquery。我已经上传了原始问题,因为我不知道如何对多个音频标签执行相同的操作音频文件。@jAndy:那个例子只有一个“添加到”功能。我看不到任何与播放音频文件相关的内容。@jAndy,在你的示例页面上它对我不起作用,即使我将脚本复制到我自己的网页上,它也不会起作用。我正在尝试使用这个插件,但我无法使用它,我在这里发布了我的问题:你能帮我吗完全
$(function(){
var birdhover = $('.birds');
var birdaudio = birdhover.find('audio')[0];
birdhover.hover(function(){
birdaudio.play();
}, function(){
birdaudio.stop();
});
});