2

I'd like to position my jQuery UI dialogs a bit better. The default "center" position puts them directly in the middle of the page, but it certainly looks better to have them offset about 70% up the page as they are in Facebook. I'm looking at the .position function but am a bit unclear what the simplest solution is.

2 Answers 2

13

For jquery-ui 1.9+:

$("#dialog").dialog({ position: { my: "center", at: "top+30%", of: window } });

For jquery-ui 1.8:

$("#dialog").dialog({ position: { my: "center", at: "top", of: window, offset: "0 30%" } });

It's something like that but play around with offset values.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Awesome, helped me out for an older system using jQ UI 1.8.x. Thanks!
5

The easiest way would be to use the position()

$("#dialog").dialog("widget").position({
       my: 'left',
       at: 'right',
       of: target
});

Or, if you already have calculated the dimensions

var x = 50; //calculate the 70%, with your own logic
var y = 100;
$("#dialog").dialog('option', 'position', [x,y]);

Or you can specify the height during initialisation of the widget

$("#dialgo").dialog({
     autoOpen: false, 
     width: 400 , 
     position: [300,200] 
});

3 Comments

I was afraid I'd have to do some calculations. I was hoping there would be a simpler way to do it.
+1 I just spent the last 30 minutes looking for the position: [300,200] part of this puzzle. Thanks!
Note: position: [300,200] does not work in 1.12.1 . The proper code is to use position: {my: 'top left', at: 'top+300 left+300', of: window}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.