javascript - JQuery UI 可调整大小/#constrain-area -> 约束不小于子 div 元素

标签 javascript jquery jquery-ui

到目前为止,JqueryUI 可以正常工作,我可以调整大小 <div></div>元素不大于其父元素,如本例所示: https://jqueryui.com/resizable/#constrain-area

这意味着我无法使蓝色区域大于橙色区域,因为 <div>blue</div><div>orange</div>的 child

我想做的恰恰相反: <div>orange</div>不应该允许将大小调整得更小,这样它仍然适合 child <div>blue</div><div>red</div>

这是一个例子: enter image description here

因为我们从右下角调整大小,所以最大减去调整大小应该是: enter image description here

DOM 树如下所示:

enter image description here

我的问题是,是否可以使用 JQueryUI 进行此类限制,如果不能,是否有人知道支持此类限制的解决方案或另一个 JavaScript 库。

最佳答案

您可以使用 JQuery 获得该行为,here you can find a jsfiddle

  var minWidth = 0;
  var minHeight = 0;

  $.each( $('#main'), function(i, divs) {
     $('div', divs).each(function() {
        var tmpWidth = $(this).position().left + $(this).width();
            if (tmpWidth > minWidth)
        minWidth = tmpWidth;
      var tmpHeight = $(this).position().top + $(this).height();
            if (tmpHeight > minHeight)
        minHeight = tmpHeight;
     });
  });
  $('.orange').resizable({
            resize : function(event, ui){
            $(this).resizable( "option", "minWidth", minWidth);
            $(this).resizable( "option", "minHeight", minHeight);
        }
    });

关于javascript - JQuery UI 可调整大小/#constrain-area -> 约束不小于子 div 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38507714/

相关文章:

javascript - 将内部 Accordion 创建为空 Accordion

javascript - 键名中的 MongoDB 点 (.)

javascript - 如何用一个常量乘以每个对象值数组?

javascript - 仅过滤 1 个菜单

javascript - 使用 Javascript 在 header 中重定向是否被认为是不好的做法?

jQuery-UI 在没有 CSS 或自定义的情况下无法在我的用户脚本中工作?

javascript - JQuery UI 自动完成选择元素速度缓慢

javascript - MongoDB - 查询数组的最后一个对象?

javascript - 选择选项时显示 div 标签 | Angular 1

javascript - 如何在我悬停鼠标的图像上显示悬停效果