Forums

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

Home Forums CSS jQuery: Animate only if class exists

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #37705
    mikes02
    Participant

    I would like to not go through the animation if the link already has the class of “active”, I have been fooling with this for a bit and can’t seem to get it to work, this is the current jQuery I am using

    // Scrolling Animation
    $('#slides li a').each(function()
    {
    $('#slides li a').click(function(e)
    {
    $('#social').fadeOut(100);

    var $anchor = $(this);
    $('html, body').stop().animate({
    scrollTop: $($anchor.attr('href')).offset().top
    }, 1500,'easeInOutExpo',function()
    {
    $('#social').fadeIn(250);
    });
    e.preventDefault();
    });
    });

    And here is the HTML

    #101487
    TheDoc
    Member

    You would just need to wrap your click function in an if statement.

    if( !$(this).hasClass('active') ) {
    // click function
    }
    #101488
    mikes02
    Participant

    Ya, I had tried that, it doesn’t work, it’s still doing the animation.

    #101492
    TheDoc
    Member
    // Scrolling Animation
    $('#slides li a').each(function()
    {
    $('#slides li a').click(function(e)
    {
    if( !$(this).hasClass('active') ) {
    $('#social').fadeOut(100);

    var $anchor = $(this);
    $('html, body').stop().animate({
    scrollTop: $($anchor.attr('href')).offset().top
    }, 1500,'easeInOutExpo',function()
    {
    $('#social').fadeIn(250);
    });
    e.preventDefault();
    }
    });
    });

    What about that?

    #101496
    mikes02
    Participant

    That worked, thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘CSS’ is closed to new topics and replies.