目前,我使用jQuery的爆炸效果,在我的气泡弹出时发出爆炸声。我希望能够一个接一个地点击一个气泡,而不必等待其他声音完成。我已经尝试使用变量来更改为不同的音频对象而没有运气。任何帮助将不胜感激!
同样的问题发生在jsfiddle:jsfiddle.net/xbrjp/1/
我的HTML
<body style="background:black;">
<style>
.circleBase {
-webkit-border-radius: 999px;
-moz-border-radius: 999px;
border-radius: 999px;
behavior: url(PIE.htc);
}
.type1 {
padding:20px;
background: white;
border:1px solid black;
color:black;
}
</style>
<div class="circleBase type1" style="display:table-cell; vertical-align:middle;">
<div align="center">Bubble 1</div></div>
<div class="circleBase type1" style="display:table-cell; vertical-align:middle;">
<div align="center">Bubble 2</div></div>
<div class="circleBase type1" style="display:table-cell; vertical-align:middle;">
<div align="center">Bubble 3</div></div>
</body>
<script>
$( ".type1" ).click(function() {
$( this ).toggle( "explode", {pieces: 50 }, 2000);
});
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://www.soundjay.com/mechanical/sounds/explosion-01.mp3');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
var audioElement2 = document.createElement('audio');
audioElement2.setAttribute('src', 'http://www.soundjay.com/mechanical/sounds/explosion-01.mp3');
//audioElement.load()
$.get();
audioElement2.addEventListener("load", function() {
audioElement2.play();
}, true);
var x = 0;
if(x == 0) {
$('.type1').click(function() {
audioElement.play();
});
x = 1;
}
if(x == 1) {
$('.type1').click(function() {
audioElement2.play();
});
x = 0;
}
$('.pause').click(function() {
audioElement.pause();
});
});
</script>
答案 0 :(得分:0)
我实际上会为每个气泡创建一个<audio>
元素:
$(document).ready(function () {
$(".type1").click(function () {
$(this).toggle("explode", {
pieces: 50
}, 2000);
$(this).find('audio').get(0).play();
});
$('.type1').each(function() {
$('<audio/>')
.attr('src','http://www.soundjay.com/mechanical/sounds/explosion-01.mp3')
.appendTo(this);
});
});