Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQueryUI对话框位置不工作,_Jquery_Jquery Ui - Fatal编程技术网

JQueryUI对话框位置不工作,

JQueryUI对话框位置不工作,,jquery,jquery-ui,Jquery,Jquery Ui,我正在使用JQueryUI对话框,并在下面创建了此函数: <script> $(document).ready(function() { $('#dialog').dialog({ autoOpen:false, width:100, height:200, position:[2250,50] });

我正在使用JQueryUI对话框,并在下面创建了此函数:

<script>
    $(document).ready(function() {
        $('#dialog').dialog({
                autoOpen:false,
                width:100,
                height:200,
                position:[2250,50]
           });


        $('.class112').click(function() {
           var msg = $(this).attr('id');
           $('#dialog').load('classSource/' + msg + '.html', function() {
           $('#dialog').dialog('open');
           });
        });
    });
</script>
结果,它在窗口的最右边创建了一个对话框,而不是在声明X的位置。但Y显示正确,因为50px在我的屏幕分辨率范围内

我想要的只是当我点击“点击”时段落中,我希望对话框显示在初始化位置,在水平滚动之后,我可能能够看到它。
我该怎么办?

我认为对话框小部件使用Position实用程序来定位自己。查看文档,您可以使用“碰撞”选项来控制此行为:

当定位元素沿某个方向溢出窗口时, 将其移动到另一个位置。与my和at类似,这接受 水平/垂直的单个值或一对,例如“翻转”、“适合”, “适合翻转”、“不适合翻转”

编辑:

是的,查看1.8.16的源代码,默认选项为“fit”:

位置:{
我的‘中心’,
在‘中心’,
碰撞:“适合”,
//确保标题栏永远不在文档之外
使用:功能(pos){
var topOffset=$(this).css(pos).offset().top;
if(拓扑偏移<0){
$(this.css('top',pos.top-topOffset);
}
}
},

您可能希望将其覆盖为“无”。

这应该可以在jQuery 1.8以上实现:

//Overriding collision detection default settings of the jQuery dialog.
$.extend($.ui.dialog.prototype.options.position, { collision: 'none' });
不幸的是,由于“\u position”函数在源代码中的工作方式,无法在单独的对话框元素上更改此设置。这意味着以下情况将不起作用:

$('#elem').dialog({
position: {
    collision: 'none'
    }
});

不过,如果将来对代码的维护没有问题,您也可能会弄乱UI对话框的源代码。

Ok这里还有另一个问题,当我水平滚动窗口并启动.dialog('open')函数时,它会以x+(水平滚动量)创建对话框。我希望它只能在指定的x和y位置创建。你能帮帮我吗?@burikuri也许你不需要指定x和y,你还需要将滚动量计算在内并减去它。请随意发布一个新问题。是的,我想减去xscroll金额。您知道如何获取xscroll金额吗?已验证。在1.8.21中,效果非常好。奇怪,但在1.8.9中没有结果。非常感谢@Andrei,它解决了我的问题
    position: {
        my: 'center',
        at: 'center',
        collision: 'fit',
        // ensure that the titlebar is never outside the document
        using: function(pos) {
            var topOffset = $(this).css(pos).offset().top;
            if (topOffset < 0) {
                $(this).css('top', pos.top - topOffset);
            }
        }
    },
//Overriding collision detection default settings of the jQuery dialog.
$.extend($.ui.dialog.prototype.options.position, { collision: 'none' });
$('#elem').dialog({
position: {
    collision: 'none'
    }
});