jQuery 使用 jQueryUI 调整大小的句柄

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15923891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:01:40  来源:igfitidea点击:

Resizable handles with jQueryUI

javascriptjqueryjquery-uiresizablehandles

提问by user2265529

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.

更具体地说,我需要那些蓝点在我的周围<div>,以便从不同的侧面调整大小。

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.

结果还可以,但我不仅需要在角落制作手柄,还需要在边框的中间制作手柄,就像第一张图片一样。

回答by Cristi Pufu

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

看看这个小提琴:http: //jsfiddle.net/j2JU6/256/

HTML:

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:

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:

JavaScript:

$('#elementResizable').resizable({
    handles: {
        'nw': '#nwgrip',
        'ne': '#negrip',
        'sw': '#swgrip',
        'se': '#segrip',
        'n': '#ngrip',
        'e': '#egrip',
        's': '#sgrip',
        'w': '#wgrip'
    }
});