1
I made a code that when starting my event, it makes a block make a move from the top down. If it keystrokes the "3" key between the pixels set during the animation, it causes the animation to be removed and receive "1 hit".
But if I keep typing all the time, it’ll add up to more than one every time I keep typing and I’ll get a lot more hits than I should. I wish there was a way to limit it to just once he could do that and block on the others, making him have only one hit.
In the Jsfiddle below, in the case of Alert, it would be as if I were typing the 3 several times the key and adding the hits. In my code there is no Alert and yes at the end he tells me the correct answers http://jsfiddle.net/m3fvL/
$(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', '');
},
})});
Could you post a Jsfiddle demo? Seeing it running makes it easy for others to give suggestions.
– Wakim
There is no way by a condition only true/false, starts the variable as false and arrow as true, if true Return false and does not execute anything.
– Marcelo Aymone
Done on Jsfiddle, I hope you understand. In the case of Alert, it would be as if I kept typing several times the key and adding the hits that in the case I would like to limit to 1. In my code there is no Alert but at the end he tells me the hits
– Lollorcaust