views:

377

answers:

2

I want to position my jQuery dialog x-pixels away from the right border of the browser. Is this anyhow possible?

http://jqueryui.com/demos/dialog/

The position option doesn't seem to have that kind of setup, but is there any other way to do it?

+1  A: 

look here: http://jqueryui.com/demos/dialog/#option-position

Initialize a dialog with the position option specified.

 $('.selector').dialog({ position: 'top' });

Get or set the position option, after init.

//getter
var position = $('.selector').dialog('option', 'position');
//setter
$('.selector').dialog('option', 'position', 'top');
dfens
+1  A: 

If you make your dialog box's position:absolute, then its taken about of the regular page flow, and you can use the left and top property to place it anywhere on the page.

$('.selector').dialog({ dialogClass: 'myPosition' });

and define the myPosition css class as:

.myPosition {
    position: absolute;
    right: 200px; <!-- use a length or percentage -->
}

You can set the top, left, right, and bottom properties for myPosition using either a length such as in pixels or percentage.

Anurag
Don't forget that it will position it relative to the first parent element whose position is specified. If none are found, it is positioned relative to the body tag. Therefore, for a dialog like this, it's important to always append it to the body tag.
atxryan
Yes, got it with this, thanks!
mruu