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

  • Home
  • SEARCH
  • 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 7594161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:20:46+00:00 2026-05-30T21:20:46+00:00

I apologize that I am very much a novice with javascript. I have sort

  • 0

I apologize that I am very much a novice with javascript. I have sort of picked up aspects of JQuery to augment my website designs but I never properly learned the fundamentals or syntax.

Here is what I want to do: When a user clicks on a a link in the list #nav the div #content will be animated up off the top of the screen by the height of #content. Then #content will be hidden. Then #content will be replaced by new content loaded in from the page that is linked to with the link the user clicked on in #nav. #content needs to remain hidden then move below the screen by the height of the viewport. Then #content will be made visible and animated back to its original location. Below is the code I mocked up but it isn’t working properly.

Thanks!

$(document).ready(function() {

$('#nav li a').click(function(){

    var toLoad = $(this).attr('href')+' #content';

    var oldHeight = $('#content').css("height");

    var viewportHeight = $(window).height();

    $('#content').animate({
        top: "-" + oldHeight
    }, 'slow');

    $('#content').hide();

    $('#content').load(toLoad);

    $('#content').animate({
        top: viewportHeight + "px"
    });

    $('#content').show();

    $('#content').animate({
        top: "0px"
    }, 'slow');

    return false;

});

});
  • 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-05-30T21:20:48+00:00Added an answer on May 30, 2026 at 9:20 pm

    What you’re asking it to perform everything after your load() only when it loads something …

    load() is async and you can see the full signature of the method in jQuery website, where it says that you can append a function that will fire when the load as completed.

    from your example just put everything after your load() inside that method…

    the final result should look like:

    var clickedAnchors = [];
    
    $(document).ready(function() {
    
        $('#nav li a').click(function() {
    
            var toLoad = $(this).attr('href')+' #content';        
            var oldHeight = $('#content').css("height");        
            var viewportHeight = $(window).height();
    
            $('#content').animate({
                top: "-" + oldHeight
            }, 'slow', function() {
    
              $('#content').hide();        
              $('#content').load(toLoad, function() {
    
    
                $('#content').animate({
                   top: viewportHeight + "px"
                });
    
                $('#content').show();        
                $('#content').animate({
                    top: "0px"
                }, 'slow');
    
              }); // close load
    
            }); // close animate
    
            return false;
    
        }); // close selector
    }); // close document.ready
    

    Remember that one of the nicer features of jQuery is cascading, so your code could actually look like this:

    var clickedAnchors = [];
    
    $(document).ready(function() {
    
        $('#nav li a').click(function() {
    
          var currentId = $(this).attr('id');
    
          if($.inArray(currentId, clickedAnchors) < 0) {
            // this anchor was not yet clicked
    
            var toLoad = $(this).attr('href')+' #content',        
                oldHeight = $('#content').css("height"),        
                viewportHeight = $(window).height();
    
            $('#content').animate({ top: "-" + oldHeight }, 'slow', function() {
    
                // after animated is completed
                $('#content')
                    .hide()
                    .load(toLoad, function() {    
    
                        $(this).animate( { top: viewportHeight + "px" }, function() {
    
                            // after animation has completed
                            $(this)
                               .show()
                               .animate({ top: "0px" }, 'slow');
    
                        });
                    });
            });
    
            // remove this anchor from being clicked again,
            // so let's add it's id into the array
            clickedAnchors.push(currentId);
          }
    
          return false;
    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize for asking such a generalized question, but it's something that can prove
Note: Now that I've typed this out, I have to apologize for the super
firstly, I very much apologize for my poorly written title of this question. So
This question might be very abstract, so apologize in advance. I have a log
I tried searching for this, but couldn't find much. It seems like something that's
I have a very strange issue, that I'm hoping someone here can help me
My question consists of multiple points that are inherently related, I apologize for that.
Alright, I am hoping someone can help me out. I apologize up front that
Bit support question. Apologies for that. I have an application linked with GNU readline.
Greetings, Apologies in advance that I have not researched this toughly enough to answer

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.