我正在尝试在 jQuery 中定位一个对话框,并且我有以下代码。它似乎没有做我期望的事情。我只需要对话框居中或出现在我 body 的左上角。
这是我的代码
agreeDialog = $j('#termsOfAgreementConfirm').dialog({
modal: true,
autoOpen:false,
resizable:false,
width : 1000,
height :400,
stack:false,
closeOnEscape:false,
title:"Terms of Usage",
open: function(event, ui) {
$j('.ui-dialog-titlebar-close').hide();
},
buttons: {
Disagree: function() {
disagree.dialog('open');
disagree.dialog('moveToTop');
},
Agree: function() {
$j(this).dialog('close');
$j.cookie("agree", "Y");
new Ajax.Request('/myballback/user/ajaxUpdateAgreementForUser',
{
onSuccess:function(resp) {
},
onError: function(resp) {
alert("Error:" + resp.toJSON());
return;
},
asynchronous:true,
evalScripts:true
});
$j(this).dialog('close');
}
}
});
var x = jQuery(agreeDialog).position().left + jQuery(agreeDialog).outerWidth();
var y = jQuery(agreeDialog).position().top - jQuery(document).scrollTop(); //agreeDialog.dialog({width:width, height:height ,position:[posX, posY]});
agreeDialog.dialog('option', 'position',[x, y]);
最佳答案
你为什么不尝试一下:
$( ".selector" ).dialog( "option", "position", ['left','top'] );
或
$( ".selector" ).dialog( "option", "position", 'center' );
关于jquery - 定位对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8526129/