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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:41:24+00:00 2026-05-30T02:41:24+00:00

I am trying to keep the <div> centered on the screen but this fails.

  • 0

I am trying to keep the <div> centered on the screen but this fails.

Here is the code:

var self = $(this);
self.animate({
    'top': ($(window).height() / 2) - (self.outerHeight() / 2),
    'left': ($(window).width() / 2) - (self.outerWidth() / 2)
}, 600, 'swing', function () {
    self.animate({
        'width': '+=200px',
        'height': '+=200px', 
        'top': ($(window).height() / 2) - (self.outerHeight() / 2), //NO UPDATE
        'left': ($(window).width() / 2) - (self.outerWidth() / 2) //NO UPDATE
    }, 600, 'linear');
});

So mainly after the second animation where the <div> grows by 200px on each direction, top and left stay the same from the first animation. I’d like the position to update as well.

What can be done here?

  • 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-30T02:41:26+00:00Added an answer on May 30, 2026 at 2:41 am

    Do take into consideration than when running the following code:

    'top': ($(window).height() / 2) - (self.outerHeight() / 2), //NO UPDATE
    'left': ($(window).width() / 2) - (self.outerWidth() / 2) //NO UPDATE
    

    The value you get from self.outerHeight() is the absolute current value (without the added amount) as jQuery will increment the size slowly to give the impression of an animation.

    To make it work you must add the amount manually:

    'top': ($(window).height() / 2) - ((self.outerHeight()+200) / 2), // notice the +200
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im really trying to keep my code clean by using the switch statement but
What I'm trying to do here is get a transition when this div is
I'm trying to use paperclip with rails 3.1 but I keep getting this routing
I'll keep it brief. I'm trying to make a div element height 100%. All
Trying to keep all the presentation stuff in the xhtml on this project and
I'm trying to keep my code clean and keep the number of files down.
I'll keep this brief. I am trying to keep a map between strings and
I'm trying to keep the bar_top_container div from wrapping it's contents no matter how
I am trying to make some sort of timeline, but I can not keep
I'm trying to show a dialog (div) that's inside another div. This way, I

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.