您可以尝试在可拖动交互上使用停止功能来更改可调整大小的参数。当我在可调整大小和可拖动交互上设置包含时遇到类似问题时,它对我有帮助。
注意:这也适用于可调整大小交互的锁定纵横比。
样本:
<div id="container" style="width: 320px; height: 240px; background-color: #000000;">
<div id="subject" style="width: 240px; height: 180px; background-color: #ffffff;">
</div>
</div>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#subject").resizable(
{
aspectRatio: 4 / 3,
minHeight: 120,
minWidth: 160,
maxHeight: 240,
maxWidth: 320
}).draggable(
{
containment: "#container",
stop: function(evt, ui) {
var container = jQuery("#container");
var subject = jQuery("#subject");
var containerPosition = container.position();
var subjectPosition = subject.position();
var relativeLeft = subjectPosition.left - containerPosition.left;
var relativeTop = subjectPosition.top - containerPosition.top;
var maxWidth = (container.width() - relativeLeft) | 0;
var maxHeight = (container.height() - relativeTop) | 0;
subject.resizable("option", "maxWidth", maxWidth);
subject.resizable("option", "maxHeight", maxHeight);
}
});
});
</script>