Resizable handles with jQueryUI
Asked Answered
S

1

18

I need to make resizable handles like in this image.

green box with resizing handles

To be more specific, I need those blue dots to be around my <div> to allow resizing from different sides.

Currently I'm using the following code:

<html>
    <head>
        <link rel="stylesheet" href="jquery-ui-1.10.2/themes/base/jquery-ui.css" />
        <script src="jquery-1.9.1.min.js"></script>
        <script src="jquery-ui-1.10.2/ui/jquery-ui.js"></script>
        <title>border</title>
        <script type="text/javascript">
            $(function() {
            $('#elementResizable').resizable({ 
                handles: {
                    'ne': '#negrip',
                    'se': '#segrip',
                    'sw': '#swgrip',
                    'nw': '#nwgrip'
                }
            });
        });
        </script>
        <style>
            #elementResizable {
                border: 1px solid #000000;
                width: 300px;
                height: 40px;
                overflow: hidden;
            }
            #nwgrip, #negrip, #swgrip, #segrip, #ngrip, #egrip, #sgrip, #wgrip {
                width: 10px;
                height: 10px;
                background-color: #ffffff;
                border: 1px solid #000000;
            }
            #segrip {
                right: -5px;
                bottom: -5px;
            }
        </style>
    </head>
    <body>
        <div id='elementResizable'>
            <h1>Full Name</h1>
            Title
            <div class="ui-resizable-handle ui-resizable-nw" id="nwgrip"></div>
            <div class="ui-resizable-handle ui-resizable-ne" id="negrip"></div>
            <div class="ui-resizable-handle ui-resizable-sw" id="swgrip"></div>
            <div class="ui-resizable-handle ui-resizable-se" id="segrip"></div> 
        </div>
    </body>
</html>

As a result i got something like this.

box with handles in corners

The result is OK, but I need to make the handles not only in corners, but also in the middle of the border, exactly like in the first image.

Supplicate answered 10/4, 2013 at 10:56 Comment(2)
why not use the 's,n,e,w' coordinates too ?Boyer
I tried, but it didn't work for me. Please see here the code jsfiddle.net/j2JU6/255 or the result-image here imageshack.us/a/img577/2481/57414673.jpgSupplicate
B
30

Take a look at this fiddle: http://jsfiddle.net/j2JU6/256/

HTML:

<div id='elementResizable'>
    <h1>Full Name</h1>
    Title
    <div class="ui-resizable-handle ui-resizable-nw" id="nwgrip"></div>
    <div class="ui-resizable-handle ui-resizable-ne" id="negrip"></div>
    <div class="ui-resizable-handle ui-resizable-sw" id="swgrip"></div>
    <div class="ui-resizable-handle ui-resizable-se" id="segrip"></div>
    <div class="ui-resizable-handle ui-resizable-n" id="ngrip"></div>
    <div class="ui-resizable-handle ui-resizable-s" id="sgrip"></div>
    <div class="ui-resizable-handle ui-resizable-e" id="egrip"></div>
    <div class="ui-resizable-handle ui-resizable-w" id="wgrip"></div>
</div>

CSS:

#elementResizable {
    border: 1px solid #000000;
    width: 300px;
    height: 40px;
    overflow: hidden;
}
#nwgrip, #negrip, #swgrip, #segrip, #ngrip, #egrip, #sgrip, #wgrip {
    width: 10px;
    height: 10px;
    background-color: #ffffff;
    border: 1px solid #000000;
}
#nwgrip {
    left: -5px;
    top: -5px;
}
#negrip{
     top: -5px;
     right: -5px;
}
#swgrip{
    bottom: -5px;
    left: -5px;
}
#segrip{
     bottom: -5px;
    right:-5px;
}
#ngrip{
     top: -5px;
    left:50%;
}
#sgrip{
     bottom: -5px;
    left: 50%;
}
#wgrip{
     left:-5px;
     top:50%;
}
#egrip{
     right:-5px;
     top:50%;
}

JavaScript:

$('#elementResizable').resizable({
    handles: {
        'nw': '#nwgrip',
        'ne': '#negrip',
        'sw': '#swgrip',
        'se': '#segrip',
        'n': '#ngrip',
        'e': '#egrip',
        's': '#sgrip',
        'w': '#wgrip'
    }
});
Boyer answered 10/4, 2013 at 12:20 Comment(1)
You sir are a gentleman and a scholar. I couldn't find a good example for this anywhere else on the internetJephum

© 2022 - 2024 — McMap. All rights reserved.