JQuery UI Dialog Positioning Center of Parent

2019-06-01 23:59发布

I have a functioning snippet as follows...

function LoadTheDialog($url) {
  $dialog = $('<div></div>');
  $dialog.html('<iframe id="theDialog" src="' + $url + '"  width="530px" height="600px" style="border: 0px;"></iframe>');
  $dialog.dialog({ width: 555, modal: true, resizable: false, draggable: false, 
    open: function (type, data) { $($dialog).parent().appendTo("body"); }
  }).dialog('widget').position({ my: "center", at: "center", of: window, collision: "none" }); 
};

no matter what I have tried thus far, the dialog always shows up at top left of the browser...

Am I missing something obvious?

I would also like to bag the static width & height and have it auto size to the size of the loaded remote content but those options do not seem to work as anticipated either...

thanks in advance.

3条回答
太酷不给撩
2楼-- · 2019-06-02 00:29

I solved this issue using this solution:

position: {my: "center", at: "center", of: window.top}
查看更多
干净又极端
3楼-- · 2019-06-02 00:33

Have you tried to also set the height in the jQuery UIDialog.
I fixed the problem by setting the height and width of the dialog to the same of the iFrame.

查看更多
The star\"
4楼-- · 2019-06-02 00:43

ok solved.

You need to call you dialog like this:

window.parent.jQuery(>>the html or variable of your dialog<<).dialog({ >>the options<<  });

so that way it gets appended to the parent document and gets back to normal positioning.

查看更多
登录 后发表回答