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');
dlg.dialog('open');

1 comment:

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.