定位 jQuery 对话框

发布于 2024-08-18 06:58:37 字数 189 浏览 3 评论 0原文

我想将 jQuery 对话框放置在距浏览器右边框 x 像素的位置。这无论如何可能吗?

http://jqueryui.com/demos/dialog/

位置选项似乎没有一种设置,但是还有其他方法吗?

I want to position my jQuery dialog x-pixels away from the right border of the browser. Is this anyhow possible?

http://jqueryui.com/demos/dialog/

The position option doesn't seem to have that kind of setup, but is there any other way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

九局 2024-08-25 06:58:37

这使对话框 div 保持在固定位置,

这对我在 IE FF chrome 和 safari 中有效,只需调用

jQuery("#dialogDiv").dialog({
    autoOpen: false, 
    draggable: true,
    resizable: false,
    height: 'auto',
    width: 500,
    modal: false,
    open: function(event, ui) {
        $(event.target).parent().css('position', 'fixed');
        $(event.target).parent().css('top', '5px');
        $(event.target).parent().css('left', '10px');
    }

});

当您想要打开对话框时,

$('#dialogDiv').dialog('open');

This keeps dialog div in fixed position

this works for me in IE FF chrome and safari

jQuery("#dialogDiv").dialog({
    autoOpen: false, 
    draggable: true,
    resizable: false,
    height: 'auto',
    width: 500,
    modal: false,
    open: function(event, ui) {
        $(event.target).parent().css('position', 'fixed');
        $(event.target).parent().css('top', '5px');
        $(event.target).parent().css('left', '10px');
    }

});

when you want dialog box open just call

$('#dialogDiv').dialog('open');
魂ガ小子 2024-08-25 06:58:37

如果您将对话框设置为 position:absolute,那么它会采用常规页面流,并且您可以使用 lefttop 属性将其放置在页面上的任何位置。

$('.selector').dialog({ dialogClass: 'myPosition' });

并将 myPosition css 类定义为:

.myPosition {
    position: absolute;
    right: 200px; /* use a length or percentage */
}

您可以设置 topleftrightbottom myPosition 的属性,使用长度(例如以像素或百分比为单位)。

If you make your dialog box's position:absolute, then its taken about of the regular page flow, and you can use the left and top property to place it anywhere on the page.

$('.selector').dialog({ dialogClass: 'myPosition' });

and define the myPosition css class as:

.myPosition {
    position: absolute;
    right: 200px; /* use a length or percentage */
}

You can set the top, left, right, and bottom properties for myPosition using either a length such as in pixels or percentage.

ゃ懵逼小萝莉 2024-08-25 06:58:37

大多数答案对我来说似乎都是解决方法,我想找到官方的 jQuery 方法来做到这一点。在阅读了 .position() 文档后,我发现它确实可以在 jQuery 小部件的初始化中完成:

$("#dialog").dialog({
    title:title,
    position:{my:"right top",at:"right+100 top+100", of:"body"},
    width:width,
    height:height
})

其中 +100 分别是距右侧和顶部的距离

Most of these answers seemed to be workarounds to me, and I wanted to find the official jQuery way to do it. After reading through the .position() docs, I found that it can indeed be done in the initialization of the jQuery widget:

$("#dialog").dialog({
    title:title,
    position:{my:"right top",at:"right+100 top+100", of:"body"},
    width:width,
    height:height
})

Where the +100 is the distance from the right and top respectively

铜锣湾横着走 2024-08-25 06:58:37

我知道答案已被接受,但以防万一有人需要更多信息:
http://salman-w.blogspot.co .uk/2013/05/jquery-ui-dialog-examples.html

$(function() {
            $("#dialog").dialog({
                position: {
                    my: "right bottom",
                    at: "right bottom",
                    of: window
                }
            });
        });

I understand the answer is already accepted but just in case if any one need more info:
http://salman-w.blogspot.co.uk/2013/05/jquery-ui-dialog-examples.html

$(function() {
            $("#dialog").dialog({
                position: {
                    my: "right bottom",
                    at: "right bottom",
                    of: window
                }
            });
        });
海风掠过北极光 2024-08-25 06:58:37

使用此代码,您可以指定顶部和左侧位置:

$('#select_bezeh_window').dialog({
    modal:true,
    resizable:false,
      draggable:false,
      width:40+'%',
      height:500 ,
      position:{
          using: function( pos ) {
                $( this ).css( "top", 10+'px' );
                $( this ).css( "left", 32+'%' );
          }
       }
 });

with this code u can specify ur top and left position:

$('#select_bezeh_window').dialog({
    modal:true,
    resizable:false,
      draggable:false,
      width:40+'%',
      height:500 ,
      position:{
          using: function( pos ) {
                $( this ).css( "top", 10+'px' );
                $( this ).css( "left", 32+'%' );
          }
       }
 });
︶葆Ⅱㄣ 2024-08-25 06:58:37

看这里:http://jqueryui.com/demos/dialog/#option-position

使用指定的位置选项初始化对话框。

 $('.selector').dialog({ position: 'top' });

初始化后获取或设置位置选项。

//getter
var position = $('.selector').dialog('option', 'position');
//setter
$('.selector').dialog('option', 'position', 'top');

look here: http://jqueryui.com/demos/dialog/#option-position

Initialize a dialog with the position option specified.

 $('.selector').dialog({ position: 'top' });

Get or set the position option, after init.

//getter
var position = $('.selector').dialog('option', 'position');
//setter
$('.selector').dialog('option', 'position', 'top');
沉鱼一梦 2024-08-25 06:58:37

这对我有用,以 10px 偏移在右上角显示对话框: position: "right-10 top+10":

$( "#my-dialog" ).dialog({
    resizable: false,
    height:"auto",
    width:350,
    autoOpen: false,
    position: "right-10 top+10"
});

This worked for me to display the dialog at the top-right corner with 10px offset: position: "right-10 top+10":

$( "#my-dialog" ).dialog({
    resizable: false,
    height:"auto",
    width:350,
    autoOpen: false,
    position: "right-10 top+10"
});
凉城凉梦凉人心 2024-08-25 06:58:37

为了固定中心位置,我使用:

open : function() {
    var t = $(this).parent(), w = window;
    t.offset({
        top: (w.height() / 2) - (t.height() / 2),
        left: (w.width() / 2) - (t.width() / 2)
    });
}

To fix center position, I use:

open : function() {
    var t = $(this).parent(), w = window;
    t.offset({
        top: (w.height() / 2) - (t.height() / 2),
        left: (w.width() / 2) - (t.width() / 2)
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文