I have a jQuery dialog box that is meant to position in the middle of the screen. However, it seems slightly off-center vertically.
Here is the code:
$('#add_box').dialog({
autoOpen: true,
width: 300,
modal: true,
resizable: false,
bgiframe:true
});
Any ideas why this won't center?
I was having the same problem. It ended up being the jquery.dimensions.js plugin. If I removed it, everything worked fine. I included it because of another plugin that required it, however I found out from the link here that dimensions was included in the jQuery core quite a while ago (http://api.jquery.com/category/dimensions). You should be ok simply getting rid of the dimensions plugin.
You must add the declaration
At the top of your document.
Without it, jquery tends to put the dialog on the bottom of the page and errors may occur when trying to drag it.
This is how I solved the issue, I added this open function of the dialog:
This now opens the dialog at the top of the screen, no matter where the page is scrolled to and in all browsers.
Digging up an old grave here but for new Google searchers.
You can maintain the position of the model window when the users scrolls by adding this event to your dialog. This will change it from absolutely positioned to fixed. No need to monitor scrolling events.
My Scenario: I had to scroll down on page to open dialog on a button click, due to window scroll the dialog was not opening vertically center to window, it was going out of view-port.
As Ken has mentioned above , after you have set your modal content execute below statement.
If content is pre-loaded before modal opens just execute this in open event, else manipulate DOM in open event and then execute statement.
It worked well for me and the best thing is that you don't include any other plugin or library for it to work.
None of the above solutions seemed to work for me since my code is dynamically generating two containting divs and within that an un-cached image. My solution was as follows:
Please note the 'load' call on img, and the 'close' parameter in the dialog call.