-1
Good afternoon! I’m new to the language, I’m trying to solve a problem using the onclick command to call an animation. Turns out I can’t make onclick work at all, let alone start/stop animation. Follow my code for analysis:
<div class="resposta3">
<div id="balao" onclick="voar()" onclick="stop()">
<img src="images/ex3/balao.png" alt="">
</div>
<script type="text/javascript">
var mexendo = document.getElementById('balao');
function mexer() {
mexendo.classList.toggle("voar");
}
function stop() {
mexendo.classList.remove("voar");
}
</script>
</div>
Follow also the animation and css part:
.resposta3{
border: solid black 3px;
width: 800px;
height: 600px;
background-image: url(../images/ex3/fundo.png);
}
#balao{
animation: voar 1s linear alternate infinite;
}
@keyframes voar {
0%{
margin-top: -50px;
}
100%{
margin-top: 30px;
}
}
If you can help me I would be very grateful. Thank you
The names of your methods are wrong. You are calling
voar()
, and in your javascript there is themexer()
.– Douglas Garrido
There are several problems in your code, you have two events onclick in the same HTML element, in one of them is calling a function fly(), but, in the script does not have this function!
– LeAndrade
Another problem mentioned by @Leandrade is that there are two events
onclick
in hisdiv
.– Douglas Garrido