Jquery - Allow the function to execute only when it is not running

2

I'm having a hard time finding a way to block multiple toggles in my code. That is when the client clicks several times on the toggle field, the field appears and disappears several times. I would like to know how I can get it to open or close the field only when the action is not running.

Toogle code:

<script>
(document).ready(function(){
   $(".botao").click(function(){
   $(this).children( ".classe" ).slideToggle();
   });
});
</script>

Thanks in advance!

    
asked by anonymous 28.11.2015 / 16:45

1 answer

1

SlideToggle has a configuration parameter that does this.

If you use .slideToggle({queue: false}); it will no longer accumulate instructions. Curiously if you load it often fast it seems to have a bug and crashes ...: /

So, as a second option, use callback complete . So:

$(document).ready(function () {
    $(".botao").click(function () {
        var $this = $(this);
        var animando = $this.data('animando');
        if (!animando) $this.children(".classe").slideToggle(function(){
            $this.data('animando', false);
        });
        $this.data('animando', true);
    });
});

jsFiddle: link

    
28.11.2015 / 17:14