jQuery Drag/Resize with CSS Transform Scale

前端 未结 13 1980
忘了有多久
忘了有多久 2020-11-27 13:39

I am applying a CSS transform (and the browser specific -webkit, -o etc):

transform: matrix(0.5 , 0 , 0, 0.5, 0 , 0);

to a div then using jQuery\'s draggable

13条回答
  •  醉梦人生
    2020-11-27 14:23

    For different resize corner

    $('.rect-item').resizable({
            handles: 'n,e,s,w,ne,se,sw,nw',
            resize: (e, ui) => {
              const zoomScale = Your scale;
              const changeWidth = ui.size.width - ui.originalSize.width; // find change in width
              const newWidth = ui.originalSize.width + changeWidth / zoomScale; // adjust new width by our zoomScale
    
              const changeHeight = ui.size.height - ui.originalSize.height; // find change in height
              const newHeight = ui.originalSize.height + changeHeight / zoomScale; // adjust new height by our zoomScale
    
              ui.size.width = newWidth;
              ui.size.height = newHeight;
    
              // here
              const posOrigin = ui.originalPosition;
              if (posOrigin.left !== ui.position.left) {
                ui.position.left = posOrigin.left - changeWidth / zoomScale;
              }
              if (posOrigin.top !== ui.position.top) {
                ui.position.top = posOrigin.top - changeHeight / zoomScale;
              }
    
            }
          });
    

提交回复
热议问题