我不想让对话框在屏幕上居中,所以我设置了框的顶部和左侧坐标。我正在定位它,使其显示在链接旁边,并且在单击之前不会最初打开。
$("#error").dialog({
bgiframe: true,
autoOpen: false,
width: 'auto',
height: 'auto',
hide: 'slide',
show: 'clip'
});
和
<div id="error" title="Error">
<div id="errorText"> </div>
</div>
从这里我想在屏幕上显示一条错误消息。例如,如果我在页面底部,我不希望用户必须向下滚动才能看到对话框。如果错误消息一直在右侧,我想在单击元素的左侧显示它。唯一的问题是因为我有自动宽度和高度,所以在显示对话框之前它似乎不知道 div 的高度/宽度;使用 $('#error').height() 或 $('#error').width()。
$("#errorText").html(request.responseText + '<p>(Esc or click to close)</p>');
var x = el.position().left + el.outerWidth();
var y = el.position().top - $(document).scrollTop();
var position = el.position();
var bottomOfDialog = position.top + heightOfTheDialog;
if(bottomOfDialog > document.height)
{
y -= heightOfTheDialog;
}
var rightSideOfDialog = position.left + widthOfTheDialog;
if(rightSideOfDialog > document.width)
{
x -= (widthOfTheDialog + el.outerWidth());
}
$("#error").dialog('option', 'position', [x, y]).dialog('open');
How do I get a proper heightOfTheDialog and widthOfTheDialog before the actual dialog is opened? Or should I be using something else?