[英]Nedd to play an audio clip and a image animation by clicking one button in HTML5 template
I've a play button in my HTML5 template. 我的HTML5模板中有一个播放按钮。 When I click the 'play' button then move an image left to right. 当我单击“播放”按钮时,然后将图像左右移动。
Now I want to play an audio clip by click on the same button. 现在,我想通过单击同一按钮来播放音频剪辑。 That means I want to say- when I'll click the play button then the image will move and the audio clip will play at the same time. 这意味着我想说-当我单击播放按钮时,图像将移动并且音频剪辑将同时播放。
the play button's class is ".move_image" 播放按钮的类别为“ .move_image”
You can write function like 您可以编写类似的功能
$('.move_image').on('click',function(){
document.getElementById('audio').play();//To Play The Audio
$('#image1').animate({
opacity: 0.25,
left: "+=50",
height: "toggle"
}, 2000, function() {
//Bring Back to original Stage
$('#image1').animate({
opacity: 1,
left: "-=50",
height: "toggle"
}, 2000);
});
});
You can refer to JSFiddle . 您可以参考JSFiddle 。 For Image Animation you can use .slide or .animate() jQuery functions. 对于图像动画,可以使用.slide或.animate()jQuery函数。
You could try something like this: 您可以尝试这样的事情:
function moveImage() {
// Code to move image
play();
}
function play() {
var audio = $('#audio');
audio.play();
}
<input type="button" value="PLAY" class=".move_image" onclick="moveImage()">
<audio id="audio" src="URL to audio file here" ></audio>
When introducing audio on Canvas I have used this library: http://www.createjs.com/#!/SoundJS SoundJS is part of the CreateJS library, works well for Flash like tweens, preloading images and sound and playing sounds. 在Canvas上引入音频时,我已经使用了该库: http: //www.createjs.com/#! / SoundJS SoundJS是CreateJS库的一部分,对于补间,预加载图像和声音以及播放声音等Flash效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.