I am trying to make a gunshot simple animation in javascript . Here is my code for the bullet fire.
JavaScript code:
function myMove() {
var elem = document.getElementById("myAnimation");
var pos = 0;
var id = setInterval(frame, 5);
function frame() {
if (pos == 350) {
clearInterval(id);
document.getElementById('myAnimation').style.display='none';
} else {
pos++;
//elem.style.top = pos + 'px';
elem.style.left = pos + 'px';
}
}
}
Html code:
<div class ="col-md-12"><div class="col-md-3"><img src="images/gun.jpg" onclick="myMove()"></div>
<div id="myAnimation" class="col-md-7">
<img src="images/Bullet.png"><br>
<img src="images/Bullet.png"><br>
<img src="images/Bullet.png"><br>
<img src="images/Bullet.png"><br>
<img src="images/Bullet.png"><br>
</div>
</div>
The problem is when I click once, all the bullets get fired simultaneously. I want the bullets to get fired one by one only when I click the trigger of gun.jpg. No other complicated scenario is required.