如何使这个可调整大小 div,可从边缘调整大小?

How to make this resizable div, resizable from edges?

我有一个可调整大小和可拖动的框(灰色)。盒子可以通过从角落拉伸来调整大小。

目前只能通过从角落拉伸来调整框的大小。我也希望能够从边缘调整它的大小。 从角落拉伸使其在宽度和高度上均匀缩放。但是,跨一条边缩放只会沿长度缩放。同时,跨另一条边缩放它,只会沿宽度缩放它。 我该如何实现?

我的代码在这里。 http://jsfiddle.net/akashdmukherjee/sa44ks9u/4/

HTML:

  <div id="outer" style="background-color: yellow; width: 600px; height: 400px; margin-left: 40px; margin-top: 50px;">


        <div class="draggable_div rot">
            <div class="rotatable">
                <div id="inner" class="resizable" style="background-color: #3C3C3C; width: 300px; height: 300px;">
                </div>
            </div>
        </div>

  </div>

  <div id="x_and_y_of_inner">Left: , Right: </div>

JS:

    $('.draggable_div').draggable();


    $( ".draggable_div" ).draggable({
      drag: function( event, ui ) {

        var left_most_cordinates = $("#outer").offset().left;
        var top_most_cordinates = $("#outer").offset().top;

        $("#x_and_y_of_inner").text( "Left: " + left_most_cordinates + " Top: " + top_most_cordinates );

        ui.position.left = Math.min( left_most_cordinates, ui.position.left );
        ui.position.top = Math.min( top_most_cordinates, ui.position.top );
      }
    });

    $('.resizable').resizable({
        aspectRatio: true,
        handles: 'ne, se, sw, nw'
    });



    $(document).on('mouseover', '.rot', function(){
        var tc = $(this);
        tc.rotatable({
            handle:tc.children('.rotate.left, .rotate.right')
        });
        return true;
    });

CSS:

.draggable_div
{
    position: relative; 
    display: -moz-inline-stack;
    display: inline-block;
    vertical-align: top;
    zoom: 1;
    *display: inline;   

    cursor: hand; 
    cursor: pointer;       
}

.resizable
{
    width: 50%;   
    border: 1px solid #bb0000;   
}
.resizable img
{
    width: 100%;   
}

.ui-resizable-handle 
{
    background: #f5dc58;
    border: 1px solid #FFF;
    width: 9px;
    height: 9px;

    z-index: 2;
}
.ui-resizable-se
{
    right: -5px;
    bottom: -5px;
}

.ui-rotatable-handle 
{
    background: #f5dc58;
    border: 1px solid #FFF;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    cursor: pointer;

    height:        10px;
    left:          50%;
    margin:        0 0 0 -5px;
    position:      absolute;
    top:           -5px;
    width:         10px;
}
.ui-rotatable-handle.ui-draggable-dragging
{
    visibility:  hidden;
}

试试这段代码,在这段代码中,我从边缘开始调整大小:

HTML

<div id='resizeDiv'><div id='handle' class="ui-resizable-handle ui-resizable-s"></div>
</div>

CSS

#resizeDiv {
    margin: 20px;
    width: 100px;
    height: 100px;
    border: 1px solid #CCC;
    background-color: #FAFAFA;

}

#handle {
    width: 100px;
    height: 10px;
    background-color: gray;
}

js

$(function() {
        $( "#resizeDiv" ).resizable({handles: {'s': '#handle'}});
    });

JSfiddle click here...

如果您想保持宽高比,则无法实现此目的。所以基本上当您从 resizable 中删除该选项时,您可以根据需要使用角在任何方向上拖动并在高度和宽度上缩放它。

$('.resizable').resizable({
    //aspectRatio: true, //comment or remove this
    handles: 'ne, se, sw, nw'
});

DEMO

简单点,不用 JavaScript 让自己复杂化。通常越简单越能保证它适用于所有浏览器。 有时"Less is More" 只需在您的 CSS 中使用它,它就会起作用。

.divName {
    resize: both;
    overflow: auto;
} 

您也可以使用resize:horizontal;resize:vertical;resize:none;

例如,如果您只想调整垂直大小而不是水平大小:

.divName {
    resize: vertical;
    overflow: auto;
} 

只需使用css 属性调整大小溢出:

div
{
    resize: both;
    overflow: auto;
}