javascript 定位 jQuery 对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15716317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:49:23  来源:igfitidea点击:

Position jQuery dialog box

javascriptjquery

提问by tcovo

I've tried a million solutions and none seem to work. I just need to push my jQuery dialog box about 50px from the top of the page. Any ideas how?

我已经尝试了一百万个解决方案,但似乎没有一个奏效。我只需要将我的 jQuery 对话框从页面顶部推送大约 50 像素。任何想法如何?

function message() {
    $("#message").dialog({
      title: 'Title here',
      draggable:false,
      minHeight:100,
      resizable: false  
    });
 }

回答by adeneo

There's a positionparameter for that, it accepts an array with X and Y coordinates :

有一个位置参数,它接受一个带有 X 和 Y 坐标的数组:

function message() {
    var myPos = [ $(window).width() / 2, 50 ];

    $("#message").dialog({
      title: 'Title here',
      draggable:false,
      minHeight:100,
      position: myPos,
      resizable: false  
    });
}

FIDDLE

小提琴

回答by tcovo

Like adeneo mentioned, dialog has a positionoption which accepts a few data types, including jQuery-UI's fancy position object.

就像前面提到的adeneo 一样,对话框有一个position选项可以接受一些数据类型,包括 jQuery-UI 的奇特位置对象

Given all the options, I think the cleanest and clearest way to specify the position you want is like this:

鉴于所有选项,我认为指定您想要的位置的最干净,最清晰的方法是这样的:

var myPos = { my: "center top", at: "center top+50", of: window };

Try it in jsFiddle

jsFiddle 中尝试

回答by Suresh Atta

Have you tried this? css code .myPosition

你试过这个吗?css代码.myPosition

.myPosition {
    position: absolute;
    top: 20px;
}

and jquery

和jQuery

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