I have a code below which loads gif animation from an array character, and loads it to class board inside the image src
.
I want to play the gif animation
only when i click on that gif displayed.
it is now playing the gif as soon as it loads the gif
How to change my code to display the gif from array as it is doing now but play the gif only when i click on it?
number = 0;
var animations = ['https://image.ibb.co/epha5A/giphy.gif',
'https://image.ibb.co/epha5A/giphy.gif',
'https://image.ibb.co/epha5A/giphy.gif'
];
function character() {
image = document.getElementById('hiddenimageid');
image.src = animations[number];
console.log(number);
number++;
}
.board {
position: absolute;
top: 4.3vh;
left: 10vw;
cursor: pointer;
}
.board img {
width: 35.3vw;
height: 45.5vh;
border-radius: 15%;
}
<body onload="character();">
<div class="board">
<img src="" id="hiddenimageid" />
</div>
</body>