Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Delay .addClass with jQuery?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43185
    Rugg
    Participant

    Howdy,

    I’m having problems combining .delay with .addClass using jQuery. My goal is to have a slight delay before the class is added, but my approach doesn’t seem to solve the issue. The class is added immediately even when I specify a delay. If anyone could suggest a solution for this, or explain to me what I’m doing incorrect…I’d be ever so thankful.

    Here is a code sample:

    $(“.button”).toggle(function() {
    $(“div”).stop().animate({top:’0′}, 600);
    $(this).delay(200).addClass(“active”);
    }, function() {
    $(“div”).stop().animate({top:’-100%’}, 600);
    $(this).delay(200).removeClass(“active”);
    });

    ALSO…I’ve added the **.stop()** before the animation attempting to prevent the next animation from firing until the current is complete. For whatever reason _(mostly my lack of knowledge on the subject)_ this fails to work. Am I writing it properly?

    #127163
    Eldeeff
    Member
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.