I'm making a game and I need a routine that disables the click at least until I finish the function.
The function is this below. When I click on the element and execute this function with touchstart
and click
I want that within div
where this element is this does not allow the function of click
until it finishes this function.
How can I do this?
$('#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 that I needed. I did so. But after the function ends I can not enable this element again to click. This element runs another function, below.
$("div#back-exit > .back").off('click');
$("div#back-exit > .back").on('click', function(e){
media.stop("chime-01");
media.stop("tada");
});