Prevent jQuery UI resizable element from covering another element?

做~自己de王妃 提交于 2019-12-01 11:08:37

The jQuery UI Resizable control has a number of events available to it, including the "resize" event.

This possibly isn't the only way to accomplish this, or even necessarily the best, but it might be one approach.

When resizing starts (which will be picked up by the resize event), get the top and/or left positions of the element you want to preserve (i.e. the one you don't want to have overlapped). I'll refer to this element as the target.

As your resized element is widened, check to see whether its size is greater than the left position of your target and if so, prevent the resize element from growing any further.

Rough example:

var targetPos = $('#myTarget').position();

    $('#myResizable').resizable({
      resize: function(event, ui){ 
        if (ui.position.left + ui.size.width > targetPos.left) {
          $(this).resizable({ maxWidth: ui.size.width });
        }
      }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!