easyui Draggable

本文详细介绍了如何使用 jQuery EasyUI 实现元素的拖拽功能,包括通过 HTML 标记和 JavaScript 初始化拖拽组件的方法。同时,还探讨了拖拽组件的各种属性设置,如光标样式、延迟时间等,并提供了示例代码。

Draggable

Override defaults with $.fn.draggable.defaults.

Usage Example

Create a draggable element from markup.

  1. <divid="dd"class="easyui-draggable"data-options="handle:'#title'"style="width:100px;height:100px;">
  2. <divid="title"style="background:#ccc;">title</div>
  3. </div>

Create a draggable element using javascript.

  1. <divid="dd"style="width:100px;height:100px;">
  2. <divid="title"style="background:#ccc;">title</div>
  3. </div>
  1. $('#dd').draggable({
  2. handle:'#title'
  3. });
Properties
NameTypeDescriptionDefault
proxynull或string(比如'clone')或functionA proxy element to be used when dragging, when set to 'clone', a clone element is used as proxy. If a function is specified, it must return a jQuery object.

The example below shows how to create a simple proxy object.

//1.默认是null

//2. 可用'clone'
$('.dragitem').draggable({ proxy: 'clone' });


//3. 可用function
$('.dragitem').draggable({ proxy: function(source){ var p = $('<div style="border:1px solid #ccc;width:80px"></div>'); p.html($(source).html()).appendTo('body'); return p; } });


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic Draggable - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../demo.css">
    <script type="text/javascript" src="../../jquery.min.js"></script>
    <script type="text/javascript" src="../../jquery.easyui.min.js"></script>

    <script>
    $(function(){
        //从此以后,光标都是文本光标了
        //$.fn.draggable.defaults.cursor = 'text';
        
        $('#dd').draggable({
            proxy : function(source){
                //console.log(source);
                
                var p = $('<div style="border:1px solid #ccc;height:'+ source.style.height + ';width:'+source.style.width+'"></div>');
                //console.log(p.html($(source).html()));
                p.html($(source).html()).appendTo('body');
                return p;

            }
        });
    });
    </script>
</head>
<body>
    <div id="dd" style="width:100px;height:100px;background:green">
    wosout
    </div>
</body>
</html>
View Code

 



null
revertbooleanIf set to true, the element will return to its start position when dragging stops.false
cursorstring

The css cursor when dragging.

 

可能的值

描述
url

需使用的自定义光标的 URL。

注释:请在此列表的末端始终定义一种普通的光标,以防没有由 URL 定义的可用光标。

default默认光标(通常是一个箭头)
auto默认。浏览器设置的光标。
crosshair光标呈现为十字线。
pointer光标呈现为指示链接的指针(一只手)
move此光标指示某对象可被移动。
e-resize此光标指示矩形框的边缘可被向右(东)移动。
ne-resize此光标指示矩形框的边缘可被向上及向右移动(北/东)。
nw-resize此光标指示矩形框的边缘可被向上及向左移动(北/西)。
n-resize此光标指示矩形框的边缘可被向上(北)移动。
se-resize此光标指示矩形框的边缘可被向下及向右移动(南/东)。
sw-resize此光标指示矩形框的边缘可被向下及向左移动(南/西)。
s-resize此光标指示矩形框的边缘可被向下移动(南)。
w-resize此光标指示矩形框的边缘可被向左移动(西)。
text此光标指示文本。
wait此光标指示程序正忙(通常是一只表或沙漏)。
help此光标指示可用的帮助(通常是一个问号或一个气球)。

 

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Basic Draggable - jQuery EasyUI Demo</title>
 6     <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
 7     <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
 8     <link rel="stylesheet" type="text/css" href="../demo.css">
 9     <script type="text/javascript" src="../../jquery.min.js"></script>
10     <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
11 
12     <script>
13     $(function(){
14         $('#dd').draggable({
15             cursor:'wait',//光标变成等待
16             handle:'#title' //拖动标题div时
17         });
18     });
19     </script>
20 </head>
21 <body>
22     <div id="dd" style="width:100px;height:100px;">
23         <div id="title" style="background:#ccc;">title</div>
24         <div id="content" style="width:80px;height:80px;background:red"></div>
25     </div>
26 </body>
27 </html>
View Code

 

 

move
deltaXnumberThe dragged element position x corresponding to current cursornull
deltaYnumberThe dragged element position y corresponding to current cursornull
handleselectorThe handle that start the draggable.null
disabledbooleanTrue to stop draggable.false
edgenumberThe drag width in which can start draggable.0
axisstringDefines the axis which the dragged elements moves on, available value is 'v' or 'h', when set to null will move across 'v' and 'h' direction.null
delaynumberDefines the delay time in milliseconds to start a drag operation.100
Events
NameParametersDescription
onBeforeDrageFires before dragging, return false to cancel this dragging.
onStartDrageFires when the target object start dragging.
onDrageFires during dragging. Return false will not do dragging actually.
onStopDrageFires when the dragging stops.
Methods
NameParameterDescription
optionsnoneReturn the options property.
proxynoneReturn the drag proxy if the proxy property is setted.
enablenoneEnable the drag action.
disablenoneDisable the drag action.

转载于:https://www.cnblogs.com/yasepix/p/6437309.html

EasyUI DraggableEasyUI框架中的一个插件,它提供了拖拽功能,可以让用户通过鼠标拖动元素来改变其位置。使用EasyUI Draggable插件,可以轻松地实现元素的拖拽功能,无需编写复杂的JavaScript代码。 使用EasyUI Draggable插件,需要引入EasyUI框架的相关文件,并在需要应用拖拽功能的元素上添加相应的class和属性。以下是使用EasyUI Draggable的基本步骤: 1. 引入EasyUI框架的CSS和JavaScript文件。 2. 在需要应用拖拽功能的元素上添加class="easyui-draggable"属性。 3. 可选:通过设置属性来自定义拖拽的行为,如设置axis属性限制只能在水平或垂直方向拖拽,设置handle属性指定拖拽的手柄元素等。 下面是一个示例代码,演示了如何使用EasyUI Draggable插件: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>EasyUI Draggable示例</title> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/easyui/dist/themes/default/easyui.css"> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/easyui/dist/jquery.easyui.min.js"></script> </head> <body> <div class="easyui-draggable" style="width: 200px; height: 200px; background-color: #ccc;"> 拖拽我! </div> </body> </html> ``` 在上述示例中,我们引入了EasyUI框架的CSS和JavaScript文件,并在一个div元素上添加了class="easyui-draggable"属性。这样,该div元素就可以被拖拽了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值