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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:51:06+00:00 2026-06-09T06:51:06+00:00

I have created a popup box class. Each popup can have a variable content,

  • 0

I have created a popup box class. Each popup can have a variable content, and appears in a variable position, depending on where the cursor is when it is open, so that the popup seems to come out from the clicked link or button.

The problem is that the popup may be partially outside the screen, if the cursor is too close to the borders. To adjust the position I need the width and height of the popup.

I tried this:

$("#" + div_id).show(400);          

var off = $("#" + div_id).offset();
                var t = off.top;
                var l = off.left;
                var h = $("#" + div_id).outerHeight();

                var w = $("#" + div_id).outerWidth();

                var docH = $(document).height();
                var docW = $(document).width();
                alert("t = "+ t + ", h = " + h + ", w " + w + ", l "+ l + ", docH " + docH + ", docW " + docW);
                if ((t + h) > docH) {
                    var h_diff = (t + h) - docH;    //difference (how much is hidden?)
                    var new_top = Math.max(10, t - h_diff - 10); //move it of the needed amout + 10 margin  (but don’t go further than 10 from top border)
                    $("#" + div_id).css("top", new_top);
                }
                if ((l+ w) > docW) {
                    var w_diff = (l + w) - docW;    //difference (how much is hidden?)
                    var new_left = Math.max(10, l - w_diff - 10); //move it of the needed amout + 10 margin
                    $("#" + div_id).css("left", new_left);
                }

The problem is that outerWidth() and outerHeight do fail, actually, because since I use the animated version of show(), the retrieved height and width are minimal. I’m quite sure that’s the reason, because everything works if I show the div immediately. Also, adding the alert to see what’s happening, I’ve found out that the popup appear only after the alert with the animation (and the alert shows minimal width and weight), while if do not add a duration to show() the popup is shown first, the the alert box appears, showing the correct values.

Any ideas?

  • 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-09T06:51:07+00:00Added an answer on June 9, 2026 at 6:51 am

    Since you are already using jQuery you can use the .poisition() method to accomplish what you are trying to do.
    http://jqueryui.com/demos/position/

    Hope this helps

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

Sidebar

Related Questions

Hi I have two related problems, i created a pop-up box that appears after
I have created some JQuery that will expand a div 'popup' on hover and
I have created an Activity that will behave like a popup menu is actually
I have created a Popup that is custom component extends Canvas i want the
Using jquery dialog I have created a popup box with a form. I am
I am new to android development. I have created a popup window which is
I have created a macro for excel which will pop up form that contains
I have created app using jQuery Mobile and need to get a Dialog box
I have to open an html form in a popup. Popup should not be
So, I have a popup information window on my site. Basically, I've created a

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.