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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:40:49+00:00 2026-06-10T15:40:49+00:00

I have a position: absolute DIV on the document. I want it to (wherever

  • 0

I have a position: absolute DIV on the document.
I want it to (wherever it is on the document) get to the center while growing to a certain size (all is being animated)
I tried to use the jQuery’s animate:

$('#el').animate({
        width: 600,
        height: 600,
        top: "-20%",
        left: "-50%"
    },1200);

with many variations but I just can’t set my mind into how the mathematics should occur.

  • 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-10T15:40:50+00:00Added an answer on June 10, 2026 at 3:40 pm

    You need to calculate the top and left based on the current window’s width and height, subtracting the target DIV’s with and height as required and divide the result by 2 to get the centre point.

    For example, to calculate the left position with a current window’s width = 1200 pixels and a DVI target width of 600 pixels you can do the following:
    (WindowWidth – DivTargetWidth) / 2 = leftPosition;
    (1200 – 600) / 2 = 300;

    The same applies to calculating the top position from the relevant height values.

    The following should work:

    var targetWidth = 600;
    var targetHeight = 600;
    var targetTopPosition = ($(window).height() - targetHeight) / 2;
    var targetLeftPosition = ($(window).width() - targetWidth) / 2;
    
    console.log(targetTopPosition);
    
    $('#el').animate({
        width: targetWidth,
        height: targetHeight,
        top: targetTopPosition,
        left: targetLeftPosition
    }, 1200);​
    

    DEMO – Centering and enlarge a DIV

    Here is the link of the full-screen version of the above demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div that is position: absolute and it contains items that get
i have a container div which is position:relative and the squares are position:absolute because
I have a Div layer like this ... <style type=text/css> <!-- #newImg { position:absolute;
I have a <div> element with position: absolute and z-index something big. I would
I have something like this currently: <div class = className style = position: absolute;
I have following HTML: <div class=olympics style=display: block; position: absolute; left: 250px; top: px;>
I have this JSF page: <div id=settingsdiv style=width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px> <h:form>
I have 2 divs A & B. div A has a position absolute to
I have this stylesheet: .pixel{ position: absolute; height: 10px; width: 10px; background-color: #ffcc00; font-size:
i have following code <div class=caption style= position:absolute; margin-top:0px> <img src=caption/img1.png /> </div> <script>

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.