I made a code that when starting my event, it makes a block make a move from top to bottom. If he presses the "3" key between the pixels set during the animation, he causes the animation to be removed and received "1 hit".
But if I keep typing all the time, it will add up to 1 each time I'm typing and I'm going to have a lot more successes than I should. I would like to limit it to only once he can do this and block the others, making him only have 1 single hit.
In the JSFiddle below, in the case of the alert, it would be like if I kept typing the 3 key several times and adding the correct answers. In my code there is no alert but in the end he tells me the correct answers link
$(function cair() {
$(".blococair").fadeTo( 500, 1 );
$(".blococair").animate({
top: fim + "px",
},{
duration: 5000,
start: function () {
inicio = window.getComputedStyle(this).top.replace('px', '');
},
progress: function (a, p, r) {
var valorAtual = p * (fim - inicio);
$(document).keyup(function(e) {
if (e.which == 53 && Math.round(valorAtual) < 295) {
} else if (e.which == 53 && Math.round(valorAtual) >= 296 && Math.round(valorAtual) <= 315) {
$('.blococair').remove();
acertos++;
}})
},
"complete" : function() {
$('.blococair').remove();
},
start: function () {
inicio = window.getComputedStyle(this).top.replace('px', '');
},
})});