javascript - 使用 jQueryUI 调整大小的句柄

标签 javascript jquery jquery-ui resizable handles

我需要像这张图片一样制作可调整大小的 handle 。

green box with resizing handles

更具体地说,我需要那些蓝点在我的 <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>

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

box with handles in corners

结果还可以,但我不仅需要在 Angular 上制作 handle ,还需要在边框中间制作 handle ,就像第一张图片一样。

最佳答案

看看这个 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'
    }
});

关于javascript - 使用 jQueryUI 调整大小的句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15923891/

相关文章:

javascript - jquery中的filter()函数

javascript - 如何通过客户端网页监控和/或限制CPU/带宽的速率?

javascript - 在子站点/子文件夹中找不到 SVG href ID

jquery .on 容器元素附加到多个选择器

jquery - 如何在周 View 和日 View 中调整 jQuery Full Calendar 中事件的宽度和位置

javascript - jQuery ("#dialog").dialog ('close' ) 无法使用单独 View 上的按钮

javascript - 为什么 waitForKeyElements 对于 Google 搜索结果需要另一个超时?

javascript - 模式关闭/隐藏时停止/暂停视频

php - 在 ajax 请求中使用 JSON 响应更新 JQuery Progressbar

jquery-ui - jQueryUI、单选按钮状态和点击事件