javascript - 加载了 ajax 调用的 Jquery ui 对话框不会水平居中

标签 javascript jquery html css ajax

我有一个对话框,一旦 ajax 调用加载了未知大小的图像,就会调用该对话框。我有最大高度和最大宽度。我发现了类似的问题,但答案并没有解决我的问题。截至目前,我将屏幕宽度除以 4 以设置 X 坐标。然而,这并不完全使窗口居中。

var windowWidth = $(window).width()
var modalCenter = windowWidth/4;
$("#userImage").dialog({
    autoOpen: false,
    modal: true,
    width: 'auto',
    create: function (event, ui) {
           $(this).css("maxWidth", "700px");
    },
    height: 'auto',
    maxHeight: 600,
    show: { effect: 'fold', duration: 250 },
    position: [modalCenter, 100],
    buttons: {
        Cancel: function () {
        $(this).dialog("close");
    },
    Crop: function () {
     var x = $('#x').val();
     var y = $('#y').val();
     var w = $('#w').val();
     var h = $('#h').val();
     if (!checkCoords())
        return false;
     $.ajax({
         url: "CropImage.aspx?x=" + x + "&y=" + y + "&w=" + w + "&h=" + h,
         cache: false
     }).done(function (html) {
         //another ajax call will get all images as a list and display them where they can be set as primary images/subImages
       })
    }
  }
});

这是一张图片:

enter image description here

最佳答案

当你的 ajax 完成后,你能重新定位对话框吗?

类似于:

Crop: function(){
    var self = $(this);
    $.ajax({...}).done(function(){
        self.position({
            my: "center",
            at: "center",
            of: window
        });
    });
}

关于javascript - 加载了 ajax 调用的 Jquery ui 对话框不会水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20411156/

相关文章:

html - child 不向 parent 拉伸(stretch)

javascript - 如何使用 jquery 通过 ajax 单击指向 php 脚本的链接?

javascript - 单击按钮时的 AJAX 请求不更新 DOM

jquery - 鼠标悬停无法正常工作

javascript - Promise 完成之前调用的方法

javascript - 在 Canvas 的底部边缘绘画时图案会移动

python - LXML 的 etree.tostring 在链接 href 属性中转义 url

javascript - C3.js Y 轴范围(最大值/最小值)不适用于条形图

javascript - 为什么我的 div 没有缩小

javascript - 在表单 id html-editor-form 中显示 HTML 值