2

我正在使用 SimpleModal Jquery 插件,效果很好!

但是,有时模态 div 的宽度和高度需要更改,所以我需要模态在页面中心自动重新定位。我发现 SimpleModal 使用它的 setPosition() 函数来做到这一点。它在模态启动时自动调用。

因此,当模态 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)
});

你有什么想法?

4

3 回答 3

4

在当前版本(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 版本,它将为这些“实用”功能提供一些方便的方法。

于 2010-07-22T21:39:47.137 回答
3

当你将一个元素(我们称之为theElement)变成一个模态时,它会被一个div#simplemodal-container. div#simplemodal-container将获得相同的尺寸theElement(实际上,它将比 高/宽 2px theElement

你没有说你实际调整大小的元素,但我猜它是theElement. 如果是这种情况,#simplemodal-container则 ' 尺寸不会更新,再次定位将没有效果。您必须明确调整容器的大小。

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

$("#simplemodal-container").css({height: newHeight, width: newWidth});

在这里我假设newHeightandnewWidththeElement新维度(如果你想遵循 simplemodal 的政策,+2)

于 2010-07-13T13:47:36.080 回答
1

这对我有用:

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


$('#mybutton').click(function() {
    //code here to resize the modal
    modal.setPosition();
});
于 2011-02-01T00:49:21.527 回答