I've got a main content div, and I'd like to centre the dialog to that div, rather than to the page. Any ideas? I know there's a position utility, but I can't work out how to use it with the dialog position options.
+3
A:
You're correct, .position()
is the way to go here, like this:
$("#dialog").dialog()
.parent() //remember .dialog() wraps the content in another <div>
.position({ my: 'center', at: 'center', of: '#parent' });
//or just .position({ of: '#parent' });
In the above #parent
it the parent element selector, you can give it a try here. You want the my
and at
properties to be center
so they're centered op top of one another, then the of
selector is the parent selector you want it centered in.
I specified all relevant options for illustration, but since center
is the default for my
and at
, you can specify just the of
like I have in the commented line above.
Nick Craver
2010-09-28 19:23:34
You make it look so easy! Thanks :)
Skilldrick
2010-09-28 19:30:08
The options are useful, as I've realised after experimentation that I actually needed `my: 'top', at: 'top'` (because if the dialog's too big, the top disappears out of the top of the browser).
Skilldrick
2010-09-28 19:33:28
@Skilldrick - I was wondering if they'd be at all helpful, I was thinking more for future users finding this, but excellent that they helped you as well :)
Nick Craver
2010-09-28 19:36:18