Below you will find a code that is used to load a gif animation from an array of characters, and then display it within a board class using the image src
.
I am looking to make the gif animation play
only when the displayed gif is clicked.
Currently, the gif is automatically playing as soon as it is loaded.
Is there a way to modify the code so that the gif is displayed from the array as it currently does, but only play when it is clicked?
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>