简单的模式调整大小和居中?

发布于 2024-09-07 07:47:57 字数 487 浏览 2 评论 0原文

我正在使用 simplemodal 来调出一个包含一些内容的模式。

在该内容中,我正在对其他一些内容进行 ajax 调用,这些内容的大小与原始内容不同(小得多),

我正在做的工作是使用 jQuery 来更改模式容器的大小。

在我的 ajax 调用的 oncomplete 部分中,我使用以下 jquery,

jQuery("#simplemodal-container").animate({ height: 550 }, 500);
jQuery("#simplemodal-container").animate({ width: 493}, 500);'

这有两个问题。

在不同的浏览器中,宽度略有不同,因此模式内容看起来不太正确,

并且模式保持其原始位置。它不会在浏览器窗口中重新居中。

有谁知道如何根据开放模式内的新内容调整 simplemodal 的大小?

非常感谢。

I am using simplemodal to bring up a modal with some content in it.

Inside that content i am making a ajax call to some other content which is a different size from the original content (quite a bit smaller)

what i'm doing that is kind of working is using jQuery to change the size of the modal container.

in the oncomplete section of my ajax call i use the following jquery

jQuery("#simplemodal-container").animate({ height: 550 }, 500);
jQuery("#simplemodal-container").animate({ width: 493}, 500);'

there is two problems with this.

in different browsers the width is slightly different so the modal content doesn't look quite right

and the modal maintains it's original position. it doesn't recenter itself in the browser window.

does anyone know how to resize simplemodal based on new content inside of a open modal?

thanks very much.

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

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

发布评论

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

评论(3

不回头走下去 2024-09-14 07:47:57

我的 SimpleModal 自动宽度/高度和居中模式代码:

$('#sampleDiv').modal({
onShow: function (dialog) {
            var h = $(window).height();
            var w = $(window).width();
            dialog.container.css('height', 'auto');
            dialog.container.css('width', 'auto');
            var h2 = dialog.container.height();
            var w2 = dialog.container.width();  
            var top = (h/2)-(h2/2)-h2;  
            var left = (w/2)-(w2/2)-w2;                                                         
            dialog.container.css('left', left+'px');
            dialog.container.css('top', top+'px');
    }
});

工作 IE、FireFox 和 Chrome。

My SimpleModal Auto Width/Height and centered modal code:

$('#sampleDiv').modal({
onShow: function (dialog) {
            var h = $(window).height();
            var w = $(window).width();
            dialog.container.css('height', 'auto');
            dialog.container.css('width', 'auto');
            var h2 = dialog.container.height();
            var w2 = dialog.container.width();  
            var top = (h/2)-(h2/2)-h2;  
            var left = (w/2)-(w2/2)-w2;                                                         
            dialog.container.css('left', left+'px');
            dialog.container.css('top', top+'px');
    }
});

Working IE,FireFox and Chrome.

意犹 2024-09-14 07:47:57

下面的示例应该适合您:

$('#modalContentTest').modal({onShow: function (dialog) {
    var sm = this;
    dialog.container.animate({height: 550, width: 493}, 500, function () {
        sm.setPosition();   
    });
}});

An example like the following should work for you:

$('#modalContentTest').modal({onShow: function (dialog) {
    var sm = this;
    dialog.container.animate({height: 550, width: 493}, 500, function () {
        sm.setPosition();   
    });
}});
酒中人 2024-09-14 07:47:57

这是我到目前为止的

功能 modalThree($type) {
var $类型;

    jQuery("#simplemodal-container").animate({ width: 250 }, 0);
    jQuery("#simplemodal-container").animate({"left": "+=200px"}, "fast");
    jQuery("#simplemodal-container").animate({"top": "-=50px"}, "fast");


    jQuery('#simplemodal-container').css({
    position:'absolute',
    left: (jQuery(window).width() - jQuery('#simplemodal-container').outerWidth())/2,
    top: (jQuery(window).height() - jQuery('#simplemodal-container').outerHeight())/2
    });


    jQuery("#dialog").load("/default/modalTwo", function()
    {
      jQuery("#dialog").modal({
      overlay:80,
      autoResize:true,
      overlayCss: {backgroundColor:"#000"}
      });
    });
}

我的网站几乎是固定宽度的,我从 ajax 调用中知道内容的大小。

我使用以下

jQuery("#simplemodal-container").animate({ width: 250 }, 0); 调整它的大小
jQuery("#simplemodal-container").animate({"left": "+=200px"}, "fast");
jQuery("#simplemodal-container").animate({"top": "-=50px"}, "fast");

它有点有效,但我想根据窗口大小计算左侧和顶部的距离。

它有效,但我不确定这是否是解决方案。

Here is what I have so far

function modalThree($type) {
var $type;

    jQuery("#simplemodal-container").animate({ width: 250 }, 0);
    jQuery("#simplemodal-container").animate({"left": "+=200px"}, "fast");
    jQuery("#simplemodal-container").animate({"top": "-=50px"}, "fast");


    jQuery('#simplemodal-container').css({
    position:'absolute',
    left: (jQuery(window).width() - jQuery('#simplemodal-container').outerWidth())/2,
    top: (jQuery(window).height() - jQuery('#simplemodal-container').outerHeight())/2
    });


    jQuery("#dialog").load("/default/modalTwo", function()
    {
      jQuery("#dialog").modal({
      overlay:80,
      autoResize:true,
      overlayCss: {backgroundColor:"#000"}
      });
    });
}

my site is pretty much a fixed width and i know the size of the content from the ajax call.

i resize it using the following

jQuery("#simplemodal-container").animate({ width: 250 }, 0);
jQuery("#simplemodal-container").animate({"left": "+=200px"}, "fast");
jQuery("#simplemodal-container").animate({"top": "-=50px"}, "fast");

it kind of works but i'd like to calculate how much left and top is has to go based on the window size.

it works but i'm not sure if it is the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文