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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:58:22+00:00 2026-06-16T19:58:22+00:00

I currently have a dialog with a bunch of options defined. It is shown

  • 0

I currently have a dialog with a bunch of options defined. It is shown when the user clicks on a button. My dialog is defined as:

    $('#newIssueDialog').dialog({
        autoOpen: false,
        modal: true,
        closeOnEscape: true,
        draggable: false,
        resizable: false,
        width: 415,
        height: 175,
        position: {my: "top", at: "bottom", of: "#btnNewIssue"}
    });

This pops my dialog up, centered below my button.
What I’d actually like to do is pop the dialog below the button, but centered on my window.

Any ideas on how to do that?

Edit: Also, is it possible to take into account the position of the window relative to the document? As in, if there are scrollbars on the page and the user has scrolled the page vertically or horizontally, can we calculate the position of the button and where we are on the page so that it is still below the button and centered?

  • 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-16T19:58:23+00:00Added an answer on June 16, 2026 at 7:58 pm

    Instead of using my, at, of you can calculate the position yourself for the left and top like this:

    $("#btnNewIssue").on("click", function() {
        var $button = $(this);
        var $dialog = $('#newIssueDialog');
    
        //var top = $button.position().top + $button.height() + ($button.outerHeight() / 2);
        var top = $button.position().top + $button.height() + (($button.outerHeight(true) - $button.height()));
        var left = ($(document).width() - ($dialog.outerWidth / 2)) / 2
    
        $dialog.dialog({
            autoOpen: true,
            modal: true,
            closeOnEscape: true,
            draggable: false,
            resizable: false,
            width: 415,
            height: 175,
            position: [left, top]
        });
    });​
    

    Using the basic HTML as example:

    <div id="newIssueDialog"> My modal dialog</div>
    <button id="btnNewIssue">Click Me</button>
    

    ​

    DEMO – Positioning dialog below button but centred of window/document

    I’m using document in the example above but you can use window instead if you want, there should be little to no difference.

    Edit

    Fixed an oversight whereby the border height, the padding and margin of the button was not included correctly.

    I saved the fiddle without adding the deduction of the height from outerHeight(true) to include the borders, padding and margins of the button as well in case the button had any specified.

    This:

    var top = $button.position().top + $button.height() + ($button.outerHeight() / 2);
    

    Should be this:

    var top = $button.position().top + $button.height() + (($button.outerHeight(true) - $button.height()));
    

    Demo has been updated as well.

    Edit

    However, I’m now running into an issue if scrollbars are present on
    the page.

    For the vertical scroll position, just deduct the current scrollTop() value at the end like this:

    var top = $button.position().top + $button.height() + ($button.outerHeight(true) - $button.height()) - $(window).scrollTop();
    

    For placing the modal in the middle horizontally you don’t need to change anything. The above code to calculate left seems to always work. However if it is an issue for you in your specific markup, please have a look at scrollLeft() which I would assume would work the same way in that you need to deduct it similar to:

    var left = (($(document).width() - ($dialog.outerWidth / 2)) / 2) - $(window).scrollLeft();
    

    or possibly

    var left = ($(window).scrollLeft() - $(document).width() - ($dialog.outerWidth / 2)) / 2;
    

    As said, the DEMO below doesn’t need it but if you do, move it around and see how it fits in.

    Please note that if your button is close to the bottom of the screen
    the modal will not be below the button as it cannot be off-screen
    but it will align the bottom of the dialog with the bottom of the
    screen instead. That is expected behaviour. You see though that if the
    button has enough room below it the dialog will always be as expected,
    just below the button.

    DEMO – Including window scroll position
    (You need to scroll down to get to the button and you can also scroll to the right to test it properly)

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

Sidebar

Related Questions

This is what I have currently: $('#dialog').dialog({autoOpen: false, buttons: [{ text: 'View Here', click:
How do you create a Browse button in a WIX dialog. I currently have
I currently have the following code: $('#loginLink, #registerLink').click(function () { dialog(this); return false; });
I currently have a popup dialog with a timetable inside it and a button
I currently have the following code. Basically, just a login page and a modal
I currently have a jQuery function which onclick opens a dialog box. This allows
I have a progress dialog which is shown during some running action. If the
Currently I have a set of fields on a page. When the button is
Currently I have customised the Wix_InstallDirDlg to enable the user to set a registry
I currently have a custom Dialog class that extends DialogPreference(which of course is 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.