jQuery Drag/Resize with CSS Transform Scale

前端 未结 13 1981
忘了有多久
忘了有多久 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:21

    For a long time I wonder why @GungFoo solution not working for me for Jquery Resizable but some people told it was worked. Finally I found out there are 4 points for using jQuery Draggable and Resizable with CSS Transform Scale:

    1. Using @GungFoo solutions!
    2. Using separate divs for draggable and resizable!
    3. Using proper CSS Transform Origin for divs!
    4. Using proper CSS Direction for divs!

    Check some of this problems:

    function resizeDiv(event, ui) {
            debugger;
            var changeWidth = ui.size.width - ui.originalSize.width; 
            var newWidth = ui.originalSize.width + changeWidth / 4; 
    
            var changeHeight = ui.size.height - ui.originalSize.height;
            var newHeight = ui.originalSize.height + changeHeight / 4; 
    
            ui.size.width = newWidth;
            ui.size.height = newHeight;
    
    };
    $('#box').resizable({
        minWidth: -($(this).width()) * 10,
        minHeight: -($(this).height()) * 10, 
        resize: resizeDiv
    });
    
    $('#box2').resizable({
        minWidth: -($(this).width()) * 10,
        minHeight: -($(this).height()) * 10, 
        resize: resizeDiv
    });
    
    $('#box3').resizable({
        minWidth: -($(this).width()) * 10,
        minHeight: -($(this).height()) * 10, 
        resize: resizeDiv
    });
    
    $('#box4').resizable({
        minWidth: -($(this).width()) * 10,
        minHeight: -($(this).height()) * 10, 
        resize: resizeDiv
    });
    .box{
      position:absolute;
      width:30px;
      height:30px;
      border:1px solid black;
      font-size:3pt;
      overflow:hidden;
      -webkit-transform:scale(4);
      direction:ltr;
    }
    #box{
      transform-origin: top left;
      top: 0;
      left:0;
    }
    #box2{
      transform-origin: bottom left;
      top: 250px;
      left:0;
    }
    #box3{
      direction:rtl;
      left: 250px;
      top: -10px;
    }
    
        
         
        
    
    
    True styles
    Bad transform-orgin
    Bad direction

    Thanks to @Guy ;)

提交回复
热议问题