0

I can add one JQuery UI Dialog centered without any issues. What I want to do is add two JQuery UI Dialogs, one on top of the other, with the center of the screen "cutting between" the two dialogs so that they're centered vertically on the screen.

If I add:

if(i > 0) {
    $("#dialog" + i).dialog("option", "position", {my: "top", at: "bottom", of: $("#dialog" + (i-1))});
}                     

then the first dialog will be centered with the second dialog under it. Is there some way to position the first dialog to be higher by half its height?

1 Answer 1

0

You could use the open event to adjust positions:

$('#dialog1, #dialog2').dialog({
    open: function() {
      var $this = $(this),
        $parent = $this.parent(),
        halfWidth = $parent.outerWidth() / 2,
        parentLeft = $parent.position().left;

      parentLeft += $this.is('#dialog1') ? (0 - halfWidth) : halfWidth;

      $parent.css({left: parentLeft});
    }
  });

The approach you are attempting would be looking for positioning dimensions that don't already exist

DEMO

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

Comments

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.