Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:39:47+00:00 2026-06-06T06:39:47+00:00

Below is some jQuery code the i wrote to make a simple animation. However

  • 0

Below is some jQuery code the i wrote to make a simple animation. However I’m SO new to it i have no idea how to condense it down and get baffled by tutorials!

<!-- Login Form Div Animation -->
<script type="text/javascript">
$(document).ready(function() {
    $('#button-active').hide();
    if ($("#LoginButton").hasClass("inactive")) {
            $("#TopLoginForm").hide();
    } else {
            $("#TopLoginForm").show();
    }
    $("#LoginButton").click( function() {
        if ($("#LoginButton").hasClass("inactive")) {
            $("#LoginButton").animate({ 
                marginTop: "-40px"
                }, 500 );
            $("#button-inactive").animate({ 
                opacity: "0"
                }, 500 );
            $('#button-inactive').remove();
            $('#button-active').hide();
            $('#button-active').delay(30).fadeIn(1000);
            $('#LoginWelcome').delay(0).fadeOut(1000);
            $('#TopLoginForm').delay(800).fadeIn(1000);
            $("#LoginButton").addClass("button");
            $("#LoginButton.button").click( function() {
                document.forms["LoginForm"].submit();
            });
         }
    }); 
});
</script>
<!-- End Login Form Div Animation -->

The live code can be seen on http://www.trainingthemlive.co.uk/temp its at the top of the page

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:39:48+00:00Added an answer on June 6, 2026 at 6:39 am

    The big thing you can do is avoid running the same query twice, if you know the results haven’t changed. Chain or cache the results of your jQuery calls! Instead of:

    $('#button-active').hide();
    $('#button-active').delay(30).fadeIn(1000);
    

    you can use the chainability of jQuery objects. In fact, you’re already doing it in the second line–why not take the extra step?

    $('#button-active').hide().delay(30).fadeIn(1000);
    

    For readability:

    $('#button-active')
        .hide()
        .delay(30)
        .fadeIn(1000);
    

    But that’s not the whole answer. Chaining is concise and great, if you need to do a bunch of stuff to one object or collection in sequence. But if you need to access one object, like button-active, at several different points during execution, you should store the query as a variable.

    var $activeButton = $('#button-active'); // a common convention is to use the $ prefix on variables storing jQuery objects, but this is arguable & optional
    

    All together, with a few other efficiency tricks:

    ;$(document).ready(function() {
        var   inactiveClass     = "inactive"
            , buttonClass       = "button"
            , fadeDuration      = 1000
            , animateDuration   = 500
            , shortDelay        = 30
            , longDelay         = 800
    
            , loginInactiveButtonAnimateTarget = {
                marginTop: -40
            }
            , inactiveButtonAnimateTarget = {
                opacity: 0
            }
    
            , loginButtonClickHandler = function() {
                document.forms["LoginForm"].submit() // not modifying this, but if this is the "TopLoginForm" then you could do this simpler
            }
    
            , $activeButton     = $('#button-active').hide() /* the .hide() method chains, so it returns the button-active object */
            , $loginButton      = $('#LoginButton')
            , $topLoginForm     = $('#TopLoginForm')
            , $loginWelcome     = $('#LoginWelcome')
            , $inactiveButton   = $('#button-inactive')
    
        if ($loginButton.hasClass(inactiveClass)) {
            $topLoginForm.hide()
        } else {
            $topLoginForm.show()
        }
        $loginButton.click(function() {
            if ($loginButton.hasClass(inactiveClass)) {
                $loginButton.animate(loginnactiveButtonAnimateTarget, animateDuration)
                $inactiveButton.animate(inactiveButtonAnimateTarget, animateDuration).remove()
                $activeButton.hide().delay(shortDelay).fadeIn(fadeDuration)
                $loginWelcome.delay(0).fadeOut(fadeDuration)
                $loginForm.delay(longDelay).fadeIn(fadeDuration)
                $loginButton.addClass(buttonClass).click(loginButtonClickHandler)
            }
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote below code, try to test if a jquery dialog get excused and
i have done some code in jquery but where i commented in this bellow
I have some jQuery/JS below. The first thing to run is the alert box
I have some jQuery code which works great in Firefox and Chrome, but does
I have some jquery code that i want to able to drag, drop, clone
I have some code in the format below that's repeated throughout my page: <div
Im experimenting with some JQuery and timing. I use the code below just for
I have the below jQuery code: $(document).ready(function () { $('#ajaxButton').click(function () { $.ajax({ url:
as you see in the code below. I have a jQuery function called externally.
Below is some html I found in this jquery tooltip tutorial, the contents inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.