jquery disable click until animation is fully complete

后端 未结 2 2041
孤独总比滥情好
孤独总比滥情好 2020-12-11 22:28

i want to disable click function untill every code in it; initialized and completed.

i read these articles and tried what they said but cant make it happen: event.pr

相关标签:
2条回答
  • 2020-12-11 23:07

    You can try this:

    var exec_a1 = true, exec_a2 = true;
    $('.ele').click(function() {
        if (exec_a1 && exec_a2) {
            exec_a1 = false;
            exec_a2 = false;
    
            $('.ele').stop().animate({'top': '0px'}, 2000, function() {
                exec_a1 = true;
            });
            $(this).stop().animate({'top': '100px'}, 4000, function() {
                exec_a2 = true;
            });
        }
        return false;
    });
    
    0 讨论(0)
  • 2020-12-11 23:25

    Use on() and off() to turn the click function on/off :

    $('.ele').on('click', animateEle);
    
    function animateEle(e) {
        $('.ele').stop().animate({'top':'0px'},2000);
        $(e.target).off('click').stop().animate({'top':'100px'},4000, function() {
            $(e.target).on('click', animateEle);
        });
    }​
    

    DEMONSTRATION

    0 讨论(0)
提交回复
热议问题