Monday, October 12, 2009

jQuery UI Dialog and Positioning

Sometimes the default and automatic center positioning of a jQuery dialog upon opening does not work.

jQuery("#dialogDiv").dialog({ height: 'auto', modal: true, width: 400, autoOpen: false, position: 'center' });

I found the following code works to position the jQuery UI dialog in the center of the screen:

var x = document.body.clientWidth / 2;
var y = document.body.clientHeight / 2;
var dlg = jQuery("#dialogDiv");
dlg.dialog('option', 'position', [x, y]); //dlg.dialog('option', 'position', 'center');

1 comment:

Anonymous said...

I already tried but it is not working.