2
I am making a game and need a routine that disables the click at least until the function finishes.
The function is this below. When I click on the element and run this function with touchstart
and click
I want you inside the div
where this element does not permit the function of click
until this function ends.
How can I do ?
$('#boxes > .box').on("touchstart", function(){
var cor = $(this.data('cor');
media.play("cor-"+cor);
}).mouseenter(function(){
clearTimeout(time);
var cor = $(this).data('cor');
if(!$(this).is('.bigsize')){
time = setTimeout(function(){
media.play("cor-"+cor);
}, 200);
}
}).on("touchstart click", function(e){
if(!$(this).hasClass("move")){
e.preventDefault();
e.stopPropagation();
$("div#escolha-e-clique").addClass("out");
var elm = $(this);
elm.addClass("move");
$("div#boxes > .box, div#boxes > .box-lock").not($(this)).addClass('toenter');
setTimeout(function(){
media.play("scroll-01-ascend");
setTimeout(function(){
elm.addClass('bigsize');
setTimeout(function(){
setTimeout(function(){
media.play("chime-01");
setTimeout(function(){
$("div#gift").addClass('anime');
var randomGift = Math.floor((Math.random() * totalGifts) + 1);
var gift = $('div#gift > .gifts > div:nth-child('+randomGift+')');
gift.addClass('active');
setTimeout(function(){
gift.addClass('rotate');
//Frase do objeto
var audio = gift.data('audio');
setTimeout(function(){
media.play(audio);
}, 1400);
}, 2000);
media.play("tada");
}, 500);
}, 250);
}, 500);
}, 500);
}, 500);
}
});
I was able to disable an element I needed. I did so. But after finishing the function I cannot enable this element again to click. This element rotates another function further down.
$("div#back-exit > .back").off('click');
$("div#back-exit > .back").on('click', function(e){
media.stop("chime-01");
media.stop("tada");
});
I am using jQuery.
– Diego Souza
It works the same way
JQuery
, but I recommend using theJavaScript
pure– MarceloBoni
Why do you recommend ?
– Diego Souza
http://i.stack.Imgur.com/ssRUr.gif http://youmightnotneedjquery.com/
– MarceloBoni
Why do YOU recommend ?
– Diego Souza
We are often excited by the facilities that a plugin or a platform represents for us programmers, so we adopt them as a source of use for absolutely EVERYTHING, this happens a lot with Jquery, at least I see this, both in the workplace and at the level of knowledge... You see, I DON’T DISAPPROVE, but I think for some basic functions, like set attribute, remove attribute, and other things that with pure JS we can easily do... AT THAT POINT I take a more skeptical approach to the benefits of using this or other libraries.
– MarceloBoni
Using this powerful tool only for 1 or 2 features that can be made with pure JS, would be something like owning a Ferrari, but only use the same exchange.
– MarceloBoni