1

我不想让对话框在屏幕上居中,所以我设置了框的顶部和左侧坐标。我正在定位它,使其显示在链接旁边,并且在单击之前不会最初打开。

$("#error").dialog({
    bgiframe: true,
    autoOpen: false,
    width: 'auto',
    height: 'auto',
    hide: 'slide',
    show: 'clip'
});

<div id="error" title="Error">
<div id="errorText">&nbsp;</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?

4

1 回答 1

4

If your goal is to show the user a message and keep them from having to scroll to discover it - which I believe is the case based on your description - you may want to consider using the jQuery BlockUI Plugin to tell the user the error message. Check out the following demos:

http://malsup.com/jquery/block/#demos

I think the growl functionality may be something you could work with.

The primary benefit here is that the error message would appear in a very consistent place and you would not need to be concerned with the exact location of the "offending" element, but could - at the same time - rest assured that the error message will always be visible to the user.

于 2009-10-19T18:43:51.007 回答