gpt4 book ai didi

jquery - 鼠标悬停时的音频

转载 作者:太空宇宙 更新时间:2023-11-04 14:08:26 24 4
gpt4 key购买 nike

它部分工作,但我如何让下面的工作与多个音频文件一起工作:

    <!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>

两个图像播放相同的声音。

最佳答案

如果您不介意使用 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.com/html5/tag_audio.asp

关于jquery - 鼠标悬停时的音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3342803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com