我可以使jquery对话框的位置与窗口大小无关吗? [英] Can I make jquery dialog position independent of window size?

查看:75
本文介绍了我可以使jquery对话框的位置与窗口大小无关吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用position属性将对话框固定在某个位置.

I'm using the position attribute to fix a dialog in a certain position.

$('#red').dialog({autoOpen: false, resizable: false, draggable: false, 
    height: 600, width:550, position: [10, 150]});

我发现,如果浏览器窗口太小,则对话框不会以(10,150)弹出,而是更高.

I find that if the browser window is too small, the dialog doesn't pop up at (10, 150), but higher.

是否有一种方法可以确保无论窗口大小如何,它都会弹出到绝对位置?

Is there a way to make sure it pops up at an absolute position regardless of the window size?

推荐答案

好像对话框小部件试图使对话框保持可见状态,并在此过程中覆盖您的position设置.您可以使用open事件来强制该问题.对话框的结构(没有无关的类等)如下:

Looks like the dialog widget is trying to keep the dialog visible and overriding your position setting in the process. You could use the open event to force the issue. The structure of the dialog (without irrelevant classes and such) is like this:

<div class="ui-dialog">
    <div class="ui-dialog-titlebar"></div>
    <div id="red"></div>
</div>

所以您可以使用这样的open处理程序:

so you could use an open handler like this:

open: function(event, ui) {
    var $dialog  = $(event.target);
    var position = $dialog.dialog('option', 'position');
    $dialog.closest('.ui-dialog').css({
        left: position[0],
        top:  position[1]
    });
}

是的,虽然有点笨拙,但它可以工作,而且当对话框不适合可见区域时,我在API中看不到任何东西可以让您控制对话框的行为.

Yes, it is a bit kludgy but it works and I don't see anything in the API that allows you to control the dialog's behavior when the dialog doesn't fit in the viewable area.

演示: http://jsfiddle.net/ambiguous/L9Deb/

这篇关于我可以使jquery对话框的位置与窗口大小无关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆