admin管理员组文章数量:1346047
It it working partially, but how do I get the below to work with multiple audio files:
<!DOCTYPE HTML>
<html>
<body>
<script language="javascript" src=".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>
Both images play the same sound.
It it working partially, but how do I get the below to work with multiple audio files:
<!DOCTYPE HTML>
<html>
<body>
<script language="javascript" src="http://code.jquery./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>
Both images play the same sound.
Share Improve this question edited Jul 27, 2010 at 12:33 oshirowanen asked Jul 27, 2010 at 10:47 oshirowanenoshirowanen 16k83 gold badges205 silver badges357 bronze badges2 Answers
Reset to default 6if you don't mind using HTML5
:
HTML
<div class="birds">
<audio src="/sounds/bird.mp3" preload="auto"></audio>
</div>
Javascript
$(function(){
var birdhover = $('.birds');
var birdaudio = birdhover.find('audio')[0];
birdhover.hover(function(){
birdaudio.play();
}, function(){
birdaudio.stop();
});
});
http://www.w3schools./html5/tag_audio.asp
updated for multiple sound files
This is what I used before:
http://plugins.jquery./project/sound
Usage:
$("#sound").sound({swf: url});
$("#sound").load(url);
$("#sound").play();
$("#sound").pause();
$("#sound").stop();
$("#sound").volume(0-100);
(taken from jQuery plugins page)
for mouseover:
$('#selector').mouseover(function() {
$("#sound").play('path/to/wav/or/mp3');
});
$('#second-selector').mouseover(function() {
$("#sound2").play('path/to/second/wav/or/mp3');
});
本文标签: jqueryAudio on mouseoverStack Overflow
版权声明:本文标题:jquery - Audio on mouseover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743823106a2545148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论