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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:54:17+00:00 2026-05-24T06:54:17+00:00

I’m trying to write my own lightbox script but I’m stuck on a problem.

  • 0

I’m trying to write my own lightbox script but I’m stuck on a problem.

The wrapper div centering is done through position: absolute and top / left positioned by calculating…

top:

_center_vertical = function() {
  return (($(window).height() - wrapper.height()) / 2) - (options.margin + options.border) + $(window).scrollTop()
}

left:

_center_horizontal = function() {
  return (($(window).width() - wrapper.width()) / 2) - (options.margin + options.border) + $(window).scrollLeft()
}

The wrapper div is centered on .load() and on $(window).resize() / $(window).scroll().

When the image is loaded and appended to wrapper, top and left is calculated using the functions above, horizontal centering is correct, but vertical centering is not. It is off by around 10px or more.

When the browser window is resized or scrolled, it calls the function which animates the centering which uses the same function to calculate the top and left. The window resize / scroll does center the image properly.

I have tried using jQuery deferred.then() to have it calculate the top / left after the image is appended, but it didn’t change anything.

Example: http://jsfiddle.net/vfMNQ/


I initially thought that the difference in top position changed when I played around with things like wrapper padding (aka my border), however, I found that I was wrong.

I added some console.log('image load height: ' + ((($(window).height() - wrapper.height()) / 2) - (options.margin + options.border)) + 'px') to .load() and .scroll() and found that the difference was oddly 21px no matter what. The default border is 10px, margin is 30… so where did the 21 come from?

I’d hate to use + 21 as a hack, but seems like nobody can figure it out.

  • 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-24T06:54:18+00:00Added an answer on May 24, 2026 at 6:54 am

    Your problem appears to be in the loading div:

    
        .lbe-loading  {
        background: #578DB2 url(/public/images/loading.gif) no-repeat center center;
        width: 32px;
        height: 32px;
        padding: 5px;
        }
        

    height:
    32 + padding: (5 * 2) = 42

    42 / 2 = 21px

    Looks like you’ve appended the image with the loading div still appended to the wrapper.

    wrapper.append(loading);
    
    ...
    
    $(function() {
    
    var img = $(new Image());
    img.load(function() {
    wrapper.append(this)    // .lbe-loading still appended here 
    .css({                  // Position wrapper. 
        ...
    });
    
    loading.remove();       // Too late. 
    

    If I remove .append(loading), it centers fine.

    Put .lbe-loading on a different div so it’s not being added to the wrapper’s height.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.