Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
Javascript 调整modal div的大小时,自动将Jquery SimpleModel重新定位到页面中心_Javascript_Jquery_Jquery Plugins_Simplemodal - Fatal编程技术网

Javascript 调整modal div的大小时,自动将Jquery SimpleModel重新定位到页面中心

Javascript 调整modal div的大小时,自动将Jquery SimpleModel重新定位到页面中心,javascript,jquery,jquery-plugins,simplemodal,Javascript,Jquery,Jquery Plugins,Simplemodal,我正在使用SimpleModal Jquery插件,它工作得很好 但是,有时需要更改modal div的宽度和高度,因此我需要modal自动将其自身重新定位到页面中心。我发现SimpleModel使用其setPosition()函数来实现这一点。当模式启动时,会自动调用它 所以我试图在modal div的维度发生变化时调用上述函数,但它不起作用: $('#mybutton').click(function() { //code here to resize the modal $

我正在使用SimpleModal Jquery插件,它工作得很好

但是,有时需要更改modal div的宽度和高度,因此我需要modal自动将其自身重新定位到页面中心。我发现SimpleModel使用其setPosition()函数来实现这一点。当模式启动时,会自动调用它

所以我试图在modal div的维度发生变化时调用上述函数,但它不起作用:

$('#mybutton').click(function() {
    //code here to resize the modal
    $.modal.impl.setPosition(); //doesn't work. note that at this point, the modal is still active (displayed)
});
你有什么想法吗?

当你把一个元素(我们称之为
元素
)放到一个模态中时,它将被一个
div#simplemodal容器
包装起来
div#SimpleModel容器
将获得与
元素
相同的尺寸(事实上,它将比
元素
高2倍/宽2倍)

你没有说你实际调整的是什么元素,但我猜是
元素
。如果是这种情况,
#SimpleModel容器
的尺寸不会更新,再次定位它将没有任何效果。您必须明确地调整容器的大小

因此,在重新调整大小和定位之前,请执行以下操作:

$("#simplemodal-container").css({height: newHeight, width: newWidth});
这里我假设
newHeight
newWidth
element
的新维度(+2,如果您想遵循SimpleModel的策略)

在当前版本(1.3.5)中,您可以在回调中重新定位对话框。例如:

$('#foo').modal({
    onShow: function (dialog) {
        var modal = this; // you now have access to the SimpleModal object

        // do stuff here

        // re-position
        modal.setPosition();
    }
});
我正在开发1.3.6版,它将为这些“实用”功能提供一些方便的方法。

这对我来说很有用:

var modal = $.modal("<div>...</div>");


$('#mybutton').click(function() {
    //code here to resize the modal
    modal.setPosition();
});
var model=$.model(“…”);
$(“#mybutton”)。单击(函数(){
//在此处编码以调整模型的大小
modal.setPosition();
});

我这样做了,然后调用$.modal.setPosition()。。。“这对我很有效。”Blaise想确认,将两条线组合在一起也对我有效$(#simplemodal容器”).css({height:newHeight,width:newWidth});右$.modal.setPosition();