0

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

my js code:

$('a').click(function(){
    // disable click
    $('div').fadeOut(400,
        function(){
            $(this)
                .css('background','yellow')
            .fadeIn(1800, function(){}
             // enable click
             );});
});

i coulda use stop() but i need disable/enable plz modify my http://jsfiddle.net/WBWrM/1/ thx

2 Answers 2

5

Add as the first line of your click callback:

if ($('div').is(':animated')) return;
Sign up to request clarification or add additional context in comments.

5 Comments

+1, this works great. I think it's a better idea then what I had suggested.
Rocket - but your suggestion works perfect on my code this one keep doing fadein/out when i click multiple times
@questionMonster - eh? It shouldn't, didn't for me when I tested in the Fiddle. Unless I'm missing something, there's really no difference in concept between what my and Rocket's solutions provide. Each just ignores any click that happens while the anim is rolling.
yea your answer is good it works perfect in single link, but when it multiple links fade doesnt stop after clicking few links fast. thanks tough!
That's because your selector (div) is far too loose. I used the code you provided, not changing selectors. div should be replaced with a selector RELATIVE to the link clicked. What that is, depends on your code. Perhaps it's a sibling, for example.
3

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');
        });
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.