jQueryUI中使用可调整大小的手柄

18

我需要制作可调整大小的手柄,就像这张图片中的一样。

带有调整大小手柄的绿色框

更具体地说,我需要将那些蓝点放置在我的 <div> 周围,以允许从不同方向进行调整大小。

目前我正在使用以下代码:

<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>

结果我得到了这样的东西。

有角落手柄的框

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


为什么不使用“南,北,东,西”坐标呢? - Cristi Pufu
我尝试过,但对我不起作用。请在此处查看代码http://jsfiddle.net/j2JU6/255/ 或结果图像http://imageshack.us/a/img577/2481/57414673.jpg - user2265529
1个回答

30

看看这个代码片段: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'
    }
});

您先生是位绅士和学者。我在互联网上找不到一个好的例子。 - Anthony

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接