jQuery disable enable click event with fade

后端 未结 2 565
-上瘾入骨i
-上瘾入骨i 2021-01-27 06:10

how can i disable click event before fadein and enable it after fadeout?

my js code:

$(\'a\').click(function(){
    // disable click
    $(\'div\').fadeO         


        
相关标签:
2条回答
  • 2021-01-27 06:25

    Add as the first line of your click callback:

    if ($('div').is(':animated')) return;
    
    0 讨论(0)
  • 2021-01-27 06:36

    Add a class to the element, and don't run the event when that class is there.

    $('a').click(function () {
        var $this = $(this);
        if ($this.hasClass('noClick')) return;
        // disable click
        $this.addClass('noClick');
        $('div').fadeOut(400, function () {
            $(this).css('background', 'yellow').fadeIn(1800, function () {
                // enable click
                $this.removeClass('noClick');
            });
        });
    });
    
    0 讨论(0)
提交回复
热议问题