简体   繁体   English

jQuery UI可通过旋转元素调整大小

[英]jQuery UI resizable with rotated element

I have a rotated element to make it resizable. 我有一个旋转的元素,使其可调整大小。 The rotation is drawn by css transform:rotate. 旋转由css transform:rotate绘制。

Here I have a problem the direction of resizing is not working properly. 在这里我有一个问题,调整大小的方向不能正常工作。

For example, when you drag the left and top corner to make it smaller, the element would be larger. 例如,当您拖动左上角和上角使其变小时,该元素将变大。 It happens at the right and top corner as well. 它也发生在右上角。

Take a look: https://codepen.io/restard222/pen/JzpYxR 看看: https : //codepen.io/restard222/pen/JzpYxR

I guess the library of jQuery UI resizable works based on position, size before rotation. 我猜想jQuery UI可调整大小的库基于旋转之前的位置,大小。

Libraries 图书馆

https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css

HTML 的HTML

<div class="rotate-canvas">
  <div class="rectangle_rotate">
    <div class="handler _se se"></div>
    <div class="handler _sw sw"></div>
    <div class="handler _ne ne"></div>
    <div class="handler _nw nw"></div>
  </div>
</div>

SCSS SCSS

.rotate-canvas{
  position: relative;
  width: 600px;
  height: 400px;
  margin: 24px auto;
  border: 1px solid;
}
.rectangle_rotate{
  position: relative;
  width: 200px;
  height: 100px;
  background: blue;
  top: 100px;
  left: 100px;
  opacity: .5;
  transform: rotate(285deg);
  &:before{
    position: absolute;
    top: 0;
    left: 0;
    content: 'top';
  }
  &:after{
    position: absolute;
    bottom: 0;
    right: 0;
    content: 'bottom';
  }
}

.handler{
  position: absolute;
  width: 10px;
  height: 10px;
  background: white;
  border: 1px solid black;
  border-radius: 50%;
  &._se{
    bottom: -5px;
    right: -5px;
  }
  &._sw{
    bottom: -5px;
    left: -5px;
  }
  &._nw{
    top: -5px;
    left: -5px;
  }
  &._ne{
    top: -5px;
    right: -5px;
  }
}

javascript javascript

var resizable_options = {
    handles    : {'se': '.se', 'sw': '.sw', 'ne': '.ne', 'nw': '.nw'}
  , aspectRatio: 200 / 100
}
$('.rectangle_rotate').resizable(resizable_options);

I know it would be better to use canvas instead of dom with css. 我知道最好使用canvas而不是dom与CSS。 But this time I need to solve it remaining the original sources. 但是这一次我需要解决它,仍然保留原始资源。

HELP MEEEEE!!! 帮助面!!!

Per the docs : 根据文档

Note: When generating your own handles, each handle must have the ui-resizable-handle class, as well as the appropriate ui-resizable-{direction} class, .eg, ui-resizable-s. 注意:生成自己的句柄时,每个句柄必须具有ui-resizable-handle类以及相应的ui-resizable- {direction}类,例如ui-resizable-s。

Update your handlers by adding <div class="ui-resizable-handle ui-resizable- , like: 通过添加<div class="ui-resizable-handle ui-resizable-更新您的处理程序,例如:

<div class="ui-resizable-handle ui-resizable-se handler _se se"></div>
<div class="ui-resizable-handle ui-resizable-sw handler _sw sw"></div>
<div class="ui-resizable-handle ui-resizable-ne handler _ne ne"></div>
<div class="ui-resizable-handle ui-resizable-nw handler _nw nw"></div>

Updated codepen: https://codepen.io/anon/pen/MxGwGp 更新的Codepen: https ://codepen.io/anon/pen/MxGwGp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM