Javascript 调整modal div的大小时,自动将Jquery SimpleModel重新定位到页面中心
我正在使用SimpleModal Jquery插件,它工作得很好 但是,有时需要更改modal div的宽度和高度,因此我需要modal自动将其自身重新定位到页面中心。我发现SimpleModel使用其setPosition()函数来实现这一点。当模式启动时,会自动调用它 所以我试图在modal div的维度发生变化时调用上述函数,但它不起作用: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 $
$('#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();