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 7984315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:13:51+00:00 2026-06-04T11:13:51+00:00

I have a div which is centred on the page that contains text loaded

  • 0

I have a div which is centred on the page that contains text loaded through an jquery ajax call. When a button is clicked it refreshes the content of that DIV:

randomEntry = function() {
    $.ajaxSetup({
        cache: false
    });

    $('article#portraits').load('random.php');
    $('#refresh').click(function() {
        event.preventDefault();
        $('article#portraits').load('random.php');
    });
};​

What I would now like to do is animate the div when the button is pressed, in the following order:

  1. button is pressed
  2. div moves off screen from right to left
  3. div content is updated
  4. div with new content moves on screen from right to left.

This example illustrates the visual effect perfectly. I have looked at the code and am able to replicate the effect with two divs, each containing unique content, but am struggling to load the ajax call into the second div.

This is what I have so far – it’s clearly incorrect, as the new content loads before the div begins to move (and doesn’t come back!):

$('#refresh').click(function() {
    event.preventDefault();
    $('article#portraits').animate({ 'margin-left' : "-100%" },1500);
    $('article#portraits').load('random.php');
    $('article#portraits').animate({ 'margin-right': "-100%" }, 1500);
};

I suspect load() isn’t the right function here, and that perhaps there needs to be a second empty div to load the content into, but I’m a bit stumped. A jsfiddle with the html/css can be found here. Many thanks.

  • 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-04T11:13:53+00:00Added an answer on June 4, 2026 at 11:13 am

    You need to use the “complete” callbacks:

    $('#refresh').click(function() {
        event.preventDefault();
        $('article#portraits').animate({ 'margin-left' : "-100%" },1500, function() {
            $('article#portraits').load('random.php', function() {
                $('article#portraits').animate({ 'margin-right': "-100%" }, 1500);
            );
        );
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with a wrapper div which contains a background image and
I have a container div which is centred at 50% of the page width.
I have a div which opens when I click a menu button, I am
I have a div which contains a number of images. I would like to
I have a div which has some text, but according to different situations this
I have a DIV in the center of my page which has margin-left and
I have a script embedded in a page, which is as follows: <script type=text/javascript>
I'd like to have on my page a div which is centered and has
I have a div that is fixed to the side of my web page.
I have a div which is position:fixed so that it it always in the

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.