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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:49+00:00 2026-05-28T04:36:49+00:00

I am currently working on a custom lightbox script and need some assistance. I

  • 0

I am currently working on a custom lightbox script and need some assistance. I have the animation for the image resizing working great, but I ran into a small problem. The lightbox is shown in the middle of the user’s screen, but as soon as I animate the width and height, it doesn’t remain in the center of the screen, and just uses the old left and top values.

Here’s the markup for the lightbox itself:

<div id="jqgal_container">
    <div id="jqgal_nav_left" class="jqgal_nav">&lt;</div>
    <div id="jqgal_main">
        <div id="jqgal_main_img"></div>
        <div id="jqgal_footer">
            <div id="jqgal_main_caption"><p></p></div>
            <div id="jqgal_thumbnav_left" class="jqgal_thumbnav">&lt;</div>
            <div id="jqgal_thumbs">
                <div id="jqgal_thumbs_container">
                    <ul></ul>
                </div>
            </div>
            <div id="jqgal_thumbnav_right" class="jqgal_thumbnav">&gt;</div>
        </div>
    </div>
    <div id="jqapp_nav_right" class="jqgal_nav">&gt;</div>
</div>

The image to be displayed is stored within the #jqgal_main_img as an <img /> element. I animate the width and height of #jqgal_main_img, but I also want to keep the whole container (#jqgal_container) centered on the screen.

My question is, how can I animate the width of the child element, yet still animate the top and left positions of the container respectively, so it appears to expand and grow from the centre?

The code to animate the width and height of the image container at the moment looks as follows:

_resizeToFit : function(img_width, img_height, compFunc)
{
    // Calculate the width and height needed:
    var req_width  = img_width;
    var req_height = img_height;

    this._elements.mainimg.animate({ width: req_width }, {
        duration: 'fast',

        complete: function() {
            $.jqgal._elements.footer.width(req_width);
            $.jqgal._elements.mainimg.animate({ height: req_height }, 'fast', function() {
               if(compFunc != undefined) { compFunc.call(this); }
            });
        },

        step : function() {


        }
    });
}
  • 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-28T04:36:50+00:00Added an answer on May 28, 2026 at 4:36 am

    Also animate the margin-left and margin-top:

      "margin-left" : ($(window).width() - req_width) / 2 
      "margin-top" : ($(window).height() - req_height) / 2
    

    If the elements CSS position is ‘absolute’, change margin-top / margin-left to top and left.

    EDIT:

    At the end of the whole ‘animate’ string, add

    .parent().animate({
              "margin-left" : )($(window).width() - req_width) / 2) + this._elements.mainimg.parent().scrollLeft(),
      "margin-top" : (($(window).height() - req_height) / 2 ) + this._elements.mainimg.parent().scrollTop()
    }}
    

    Or in the callback function:

    $(this).parent().animate({...});
    

    For ease, it might be best to set variables holding the elements too…

    $this = this._elements.mainimg;
    $parent = $this.parent();
    

    Then the parent animate() data would look like this:

             "margin-left" : )($(window).width() - req_width) / 2) + $parent.scrollLeft(),
      "margin-top" : (($(window).height() - req_height) / 2 ) + $parent.scrollTop()
    }}
    

    Which is a little easier to read!

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

Sidebar

Related Questions

I am currently working on some simple custom allocators in c++ which generally works
I`m currently working on a script, and I have the following situation. function somnicefunction()
I'm currently working on a plug-in for Eclipse that translates some custom Java code
I'm currently working on a custom module in which I have a controller extending
I'm currently working on several custom ASPX server controls. Of course these controls do
SO. I'm working with the OCS UCCAPI, developing a custom OCS client. I'm currently
Currently working on a VBScript to automate some of the dirty PST ingestion work
I'm currently working on creating a custom connection provider for HNibernate very similar to
I'm currently working on a Visual Studio integration project for VS2010 (a custom highlighter)
I'm currently working on a wordpress 2.9.2 plugin (my first) that creates additional custom

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.