JS drag and Drop plugin development detailed tutorial

Source: Internet
Author: User
Tags constructor extend

One, JS drag-and-drop plug-in principle

What is the common drag-and-drop operation? The whole process has a few steps:

1, click the dragged element

2, hold down the mouse, move the mouse

3, drag and drop elements to a certain position, release the mouse

The process here involves three DOM events: Onmousedown,onmousemove,onmouseup.    So the basic idea of drag-and-drop is:

1, click the dragged element to trigger onmousedown

(1) To set the drag of the current element to true, indicating that you can drag

(2) to record the coordinates of the current mouse x,y

(3) record the coordinates of the current element x,y

2, move the mouse trigger onmousemove

(1) to determine whether the element can be dragged, if it is, enter step 2, or return directly

(2) If the element can be dragged, set the coordinates of the element
The x coordinate of the
element = The horizontal distance of the mouse movement + element original X coordinate = mouse now x coordinate-mouse before the X coordinate + element original X coordinate

element's Y coordinate = mouse movement transverse distance + element original Y coordinate = mouse now sit on y Superscript-Mouse y-coordinate + element original y-coordinate

3, release mouse trigger OnMouseUp

(1) Set mouse drag state to False

Two, the most basic effect based on the principle

Before implementing the basic effect, there are a few things to note:

1, the element wants to be dragged, and its Postion property must be relative or absolute

2, Getting the coordinates of the mouse through Event.clientx and Event.clienty

3, onmousemove is bound to the document element rather than dragging the element itself, which resolves the problem of delay or stop movement caused by quick drag
The
code is as follows:

Var dragobj = document.getelementbyid ("test");
dragobj.style.left =  "0px";
dragobj.style.top =  "0px";
var mousex, mousey, objx, objy;
var dragging = false; dragobj.onmousedown = function  (event)  {    event = event  | |
 window.event;
    dragging = true;
    dragObj.style.position =  "relative";
    mouseX = event.clientX;
    mouseY = event.clientY;
    objx = parseint (DragObj.style.left);
    objy = parseint (DragObj.style.top); } document.onmousemove = function  (event)  {    event = event  | |
 window.event;     if  (dragging)  {         Dragobj.style.left&nbsP;= parseint (EVENT.CLIENTX - MOUSEX + OBJX)  +  "px";         dragobj.style.top = parseint (event.clientY -
 MOUSEY + OBJY)  +  "px";    &NBSP} document.onmouseup = function  ()  {    
dragging = false; }


Third, Code abstraction and optimization

The above code to make plug-ins, to abstract them out, the basic structure is as follows:

; (Function (window, undefined) {
function Drag (ele) {}
window. Drag = Drag;
}) (window, undefined);


The code is wrapped with a self executing anonymous function, internally defining the drag method and exposing it to the global, directly calling drag, and passing in the dragged element.

First, the simple encapsulation of some common methods:

;  (function  (window, undefined)  {    var dom = {         //Binding Event         on:  function  (Node, eventname, handler)  {             if  (node.addeventlistener)  {        
        node.addeventlistener (Eventname, handler);             }              else {          
      node.attachevent ("on"  + eventname, handler);             }          },         //gets the style of the element         getStyle: function  node,  stylename)  {            var 
realstyle = null;             if  (window.getComputedStyle)  {                
Realstyle = window.getcomputedstyle (Node, null) [stylename];             }              else if  (node.currentstyle)  {                 realstyle = node.currentstyle[
StyleName];             }              return realStyle;
       &NBSP},         //gets the style of the setting element         setCss: function  (node, css)  {  
          for  (VAR KEY IN CSS)  {                 node.style[key
] = css[key];             }       
  }     };        window.
drag = drag; }) (window, undefined);


in a drag-and-drop operation, there are two objects: the dragged object and the mouse object, we define the following two objects and their corresponding actions:

First drag the object, it contains an element node and drag before the coordinates x and y:

Function dragelement (node)  {    this.node = node;//dragged element node  
   this.x = 0;//drag before the x-coordinate     this.y = 0;//drag before the y-coordinate} dragelement.prototype = {    constructor: dragelement,      init: function  ()  {                               This.setelecss ({             left: ) Dom.getstyle (node,  "left"),              "Top":  dom.getstyle (node,  "top")        &nbsp)     
    .setxy (Node.style.left, node.style.top);    &NBSP},     //set the current coordinates     setxy: function  (x, y)  {         This.x = parseint (x)  | |
 0;         this.y = parseint (y)  | |
 0;
        return this;    &NBSP},     //set the style of the element node     setelecss: function   (CSS)  {        dom.setcss (THIS.NODE, CSS)   
      return this;    &NBSP}}



Another object is the mouse, which contains the x and Y coordinates:

function Mouse () {
this.x = 0;
This.y = 0;
}
Mouse.prototype.setXY = function (x, y) {
this.x = parseint (x);
This.y = parseint (y);
}



This is the two objects defined in the drag-and-drop operation.



If a page can have multiple drag-and-drop elements, what should be noted:

1, each element corresponding to a Drag object instance

2, each page can only have a drag in the element

To do this, we define a single object to save the associated configuration:

var draggableconfig = {
zindex:1,
draggingobj:null,
mouse:new Mouse ()
};


has three properties in this object:

(1) ZIndex: The ZIndex property used to assign to a drag object, when two drag objects overlap, causing the current drag-and-drop object to be blocked, and setting the ZIndex to appear at the top level

(2) Draggingobj: Saves the object being dragged, removing the previous variable used to determine whether it can be dragged, and by draggingobj to determine whether the current can be dragged and the corresponding drag object

(3) Mouse: A unique mouse object that holds information such as the coordinates of the current mouse

 

Finally binds the Onmousedown,onmouseover,onmouseout event, consolidating the preceding code as follows:

;  (function  (window, undefined)  {             var dom = {                 //Binding Event                  on: function  (Node, eventname, handler)  {                     if  (Node.addeventlistener)  {                         node.addeventlistener (eventName, 
handler);                      }                      else {                         node.attachevent ("On"  + eventName, 
handler);                      }                 }
,                 //gets the style of the element                 getstyle:  function  (node, stylename)  {          
          var realStyle = null;                      if  (WindOw.getcomputedstyle)  {                         realStyle = 
window.getComputedStyle (Node, null) [stylename];                      }                      else if  (node.currentstyle)  {                         
realstyle = node.currentstyle[stylename];                      }                 
    return realStyle;                  },                  //gets the style of the settings element                  setcss: function   (NODE, CSS)  {                     for  (var key in css)  {                      
   node.style[key] = css[key];                   
  }                 }
            };             //#region   Drag element class              function dragelement (node)  {    
            this.node = node;                 this.x =
 0;                 this.y =
 0;             }              dragelement.prototype = {                 constructor: dragelement,                  init: function  ()  {                                           this.setelecss ({                          "Left":  dom.getstyle (node,   "left"),                           ' top ':  dom.getstyle (node,  "top")                     &NBSP})                     
 .setxy (Node.style.left, node.style.top);                &NBSP},                  setXY: function  (x, y)  {                     this.x = parseint (x)  | |
 0;                      this.y = parseint (y)  | |
 0;                   
  return this;                &NBSP},                  setelecss: function   (CSS)  {                     dom.setcsS (THIS.NODE, CSS);                   
  return this;                 }              }              //#endregion             // #region   Mouse Element             function mouse ()  {                this.x
 = 0;                 this.y =
 0;             }              mouse.prototype.setxy = function  (x, y)  {        
        this.x = parseint (x);                 this.y =
 parseint (y);             }              //#endregion              //drag and drop configuration             var  draggableconfig = {                 zindex: 1,                  draggingobj: null,                  mouse: new mouse ()             };             function drag (ele)  {                 this.ele =
 ele;                 function  MouseDown (event)  {                     var ele = event.target | |
 event.srcElement;                   
  draggableconfig.mouse.setxy (Event.clientx, event.clienty);                      draggableconfig.draggingobj = new dRagelement (ele);                      draggableconfig.draggingobj                          .setxy (ele.style.left,  Ele.style.top)                          .setelecss ({                               "ZIndex":  draggableconfig.zindex++,                                "position":  "relative"                          });                 }                                   ele.onselectstart = function   ()  {                     //prevents text in the object from being selected           
          return false;                 }                  dom.on (ele,  "
MouseDown ",  mousedown);             } &nbsP;           dom.on (document,  "MouseMove",  function  (event)  {                 if  (draggableconfig.draggingobj)  {                     var mouse =  Draggableconfig.mouse,                          draggingObj = 
Draggableconfig.draggingobj;                      draggingobj.setelecss ({                          "Left":  parseint (Event.clientx  - mouse.x + d raggingobj.x)  +  "px",                           "Top":  parseint (Event.clienty  - MOUSE.Y + DRAGGINGOBJ.Y)  +  "px"        
             });                 }             &NBSP})              dom.on (document,  "MouseUp", function  (event)  {                 draggableconfig.draggingobj
 = null;            &NBSP})             &nbsP;window.
drag = drag;        &NBSP}) (window, undefined);


Call method: Drag (document.getElementById ("obj"));

Note that in order to prevent text from being selected in the dragged element, return false through the Onselectstart event handler to handle the problem.

Iv. Expansion: Effective drag-and-drop elements

Some of our common drag-and-drop effects are likely to be this:

The top of the frame is able to drag and drop operation, the content area is not dragged, how to achieve this effect:

First, optimize the drag-and-drop element object as follows, adding a target element target, which means the dragged object, in the login box above, is the entire login window.

The drag element that is logged and set coordinates is the target element, but it is not a valid part of the entire part that is dragged. We add Class draggable in the HTML structure for the dragged active area to effectively drag regions:

<div id= "obj1" class= "dialog" style= "position:relative;left:50px" >
<div class= "header draggable" >< c2/> Drag effective elements
</div>
<div class= "Content" >
drag Objects 1
</div>
&L T;/div>


Then modify the drag method as follows:

Function&nbsp;drag (ele) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;dragNode&nbsp;=&nbsp; (Ele.queryselector (". Draggable ") &nbsp;| |
&nbsp;ele); &nbsp;&nbsp;&nbsp;&nbsp;dom.on (dragnode,&nbsp; "MouseDown",&nbsp;function&nbsp; (event) &nbsp;{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;dragelement&nbsp;=&nbsp;draggableconfig.dragelement&nbsp;=&nbsp;new
&nbsp;dragelement (ele); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;draggableconfig.mouse.setxy (Event.clientX,&nbsp;event.clientY)
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;draggableconfig.dragelement &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setxy (dragelement.target.style.left,&nbsp; DragElement.target.style.top) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Settargetcss ({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "ZIndex": &nbsp;draggableconfig.zindex++, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "position":&nbsp; "relative" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}); &NBSP;&NBSP;&NBSP;&NBSP}). On (dragnode,&nbsp; "MouseOver",&nbsp;function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;dom.setcss (this,&nbsp;draggablestyle.dragging); &NBSP;&NBSP;&NBSP;&NBSP}). On (dragnode,&nbsp; "Mouseout",&nbsp;function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;dom.setcss (This,&nbsp;draggablestyle.defaults);
&nbsp;&nbsp;&nbsp;&nbsp;}); }

The main modification of


is that the node that is bound MouseDown becomes a valid element that contains the Draggable class, and the entire element is a valid element if it does not contain draggable.

V, performance tuning and summarization

Because onmousemove is calling, there are some performance issues that we can delay by settimout to bind onmousemove events. The improved move function is the following

Function&nbsp;move (event) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (draggableconfig.dragelement) &nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mouse&nbsp;=&nbsp;draggableconfig.mouse, &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragElement&nbsp;=&nbsp;draggableConfig.dragElement; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragelement.settargetcss ({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Left": &nbsp;parseint (event.clientx&nbsp;-&nbsp;mouse.x&nbsp;+&nbsp; Dragelement.x) &nbsp;+&nbsp; "px", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "top": &nbsp;parseint (EVENT.CLIENTY&NBSP;-&NBSP;MOUSE.Y&NBSP;+&NBSP;DRAGELEMENT.Y) &nbsp;+&nbsp; "px" &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dom.off (document,&nbsp; "MouseMove", &nbsp;move); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;settimeout (function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&Nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dom.on (document,&nbsp; "MouseMove", &nbsp;move);
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;},&NBSP;25); &NBSP;&NBSP;&NBSP;&NBSP}}


Summary:

The implementation of the entire drag-and-drop plug-in is actually very simple, mainly to pay attention to some of the

1, the realization of the idea: the element drag position change is equal to the mouse change distance, the key is to get the mouse changes and elements of the original coordinates

       2, settimeout to delay loading of onmousemove events to provide performance

six, jquery plug-ins

Simply encapsulate it as a jquery plug-in, primarily by replacing the associated Dom method with the JQuery method to manipulate the

;&nbsp; (function&nbsp; ($,&nbsp;window,&nbsp;undefined) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;//#region &nbsp; Drag element class &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;dragelement (node) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.target&nbsp;=&nbsp;node; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node.onselectstart&nbsp;=&nbsp;function&nbsp; () &nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//prevents text in the object from being selected &nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; dragelement.prototype&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructor:&nbsp; Dragelement, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setXY:&nbsp;function&nbsp; (x,&nbsp;y) &nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.x&nbsp;=&nbsp;parseint (x) &nbsp;| |
&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&Nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.y&nbsp;=&nbsp;parseint (y) &nbsp;| |
&nbsp;0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;settargetcss :&nbsp;function&nbsp; (CSS) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ (
this.target). css (CSS);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp} &nbsp;&nbsp;&nbsp;&nbsp;//#endregion &nbsp;&nbsp;&nbsp;&nbsp;//#region &nbsp; Mouse element &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;mouse () &nbsp;{&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.x&nbsp;=&nbsp;0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.y&nbsp;=&nbsp;0; &NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;Mouse.prototype.setXY&nbsp;=&nbsp;function&nbsp; (X,&nbsp;y) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;this.x&nbsp;=&nbsp;parseint (x);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.y&nbsp;=&nbsp;parseint (y); &NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;//#endregion &nbsp;&nbsp;&nbsp;&nbsp;//Drag and drop configuration &nbsp;&nbsp;&nbsp;
&nbsp;var&nbsp;draggableconfig&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zindex:&nbsp;1, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragelement:&nbsp;null, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;mouse:&nbsp;new&nbsp;mouse () &nbsp;&nbsp;&nbsp;&nbsp;}; &nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;draggablestyle&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dragging:&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor:&nbsp; "Move" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;defaults: &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor:&nbsp; "Default" &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;var&nbsp; $document &nbsp;=&nbsp;$ (document); &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;drag ($ele) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var
&nbsp; $dragNode &nbsp;=&nbsp; $ele. Find (". draggable"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $dragNode &nbsp;=&nbsp; $dragNode. length&nbsp;&gt;&nbsp;0&nbsp;
&nbsp; $dragNode &nbsp;:&nbsp; $ele;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $dragNode. On ({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "MouseDown":&nbsp;function&nbsp; (Event ) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var
&nbsp;dragelement&nbsp;=&nbsp;draggableconfig.dragelement&nbsp;=&nbsp;new&nbsp;dragelement ($ele. Get (0)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DraggableConfig.mouse.setXY (Event.clientx,&nbsp;event.clienty); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Draggableconfig.dragelement &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setxy (dragelement.target.style.left,&nbsp; DragElement.target.style.top) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.settargetcss ({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "ZIndex": &nbsp;draggableconfig.zindex++, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "position":&nbsp; "relative" &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "MouseOver":&nbsp;function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ (This)
. CSS (draggablestyle.dragging); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Mouseout":&nbsp;function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ (this). CSS (draggablestyle.defaults); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &NBSP;&NBSP}) &nbsp;&nbsp;&nbsp;&nbsp} &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;move (event) &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (draggableconfig.dragelement) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mouse&nbsp;=&nbsp;draggableconfig.mouse, &NBsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragelement&nbsp;
=&nbsp;draggableconfig.dragelement; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragelement.settargetcss ({&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Left": &nbsp;parseint ( Event.clientx&nbsp;-&nbsp;mouse.x&nbsp;+&nbsp;dragelement.x) &nbsp;+&nbsp; "px", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Top": &nbsp;parseint (event.clienty&nbsp;- &NBSP;MOUSE.Y&NBSP;+&NBSP;DRAGELEMENT.Y) &nbsp;+&nbsp; "px" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $document. Off ("MouseMove", &nbsp;move);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;settimeout (function&nbsp; () &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $document. On ("MouseMove", &nbsp;move);
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;},&NBSP;25); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp} &nbsp;&nbsp;&nbsp;&nbsp; $document. On ({&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "MouseMove": &nbsp;move, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; "MouseUp":&nbsp;function&nbsp; () &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;draggableConfig.dragElement&nbsp;=&nbsp;null;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;$.fn.drag&nbsp;=&nbsp;function&nbsp; (options) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;drag (this); &NBSP;&NBSP;&NBSP;&NBSP}}) (jquery,&nbsp;window,&nbsp;undefined)



jquery Drag-and-drop plug-ins


has always been very confusing to the location of JS get elements: A client, an offset, a scroll.
plus the major browsers are not compatible, alas, make the elder brother Dizzy.
and many page effects use these locations. You have to practice, you have to remember.

Let's say this simple drag-and-drop plug-in based on jquery.   &NBSP

By convention, let's talk about the principle of drag-and-drop, and the steps of doing this:
What is drag? See the name to know: is to drag a dongdong to drag. Put it on our dom and change its position.
It has only two difficulties: 1, how to know is in tow? 2, how to know where to drag, dragged to where?
In fact, this is not difficult, after all, both are the basis of things, the key is skilled.

into JS, we have a drag-and-drop effect, roughly the following steps:

1, let elements capture events (in general, nothing more than MouseDown, MouseMove, MouseUp)
2, when MouseDown, The tag starts dragging, and gets the position of the element and mouse.
3, in the MouseMove, constantly get the new location of the mouse, and through the corresponding location algorithm, to reposition the element position.
4, in the MouseUp, the end of drag ... And then the cycle.

In the middle, a place to note: The dragged element needs to be positioned at least relative or absolute, otherwise the drag will not be effective.

OK, no more, no code, no truth. The corresponding explanation is in it:


&lt;! doctype&nbsp;html&nbsp;public&nbsp; "-//w3c//dtd&nbsp;xhtml&nbsp;1.0&nbsp;transitional//en" &nbsp; "http://
Www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "&gt; &lt;html&nbsp;xmlns=" http://www.w3.org/1999/xhtml "&gt; &lt;head&gt; &lt;meta&nbsp;http-equiv= "Content-type" &nbsp;content= "Text/html;&nbsp;charset=utf-8"/&gt; &lt;title &gt;Jeremy&nbsp;&nbsp;-&nbsp;&nbsp;DragDrop&nbsp;Test&nbsp;!&lt;/title&gt; &lt;meta&nbsp;name= "keywords" &nbsp; content= "JavaScript Free Drag class" &nbsp;/&gt; &lt;script&nbsp;type= "Text/javascript" &nbsp;src= "Jquery-1.4.2.min.js" &gt; &lt;/script&gt; &lt;script&nbsp;type= "Text/javascript" &gt; (function ($) {&nbsp;&nbsp;&nbsp;&nbsp;$.extend ({&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//get mouse Current coordinates &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mousecoords:function (EV) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (ev.pageX&nbsp;| | &nbsp;ev.pagey) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;{x: Ev.pagex,&nbsP;y:ev.pagey};} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;x:ev.clientx&nbsp;+&nbsp;document.body.scrollleft&nbsp;-&nbsp;document.body.clientleft , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y:ev.clientY&nbsp;+&nbsp; Document.body.scrolltop&nbsp;&nbsp;-&nbsp;document.body.clienttop &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;};
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//get style value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getstyle:function (obj,styleName) &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp; Obj.currentstyle&nbsp;?&nbsp;obj.currentstyle[stylename]&nbsp;:&nbsp;document.defaultview.getcomputedstyle (obj
, null) [StyleName]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;obj.currentstyle&nbsp;?&nbsp;obj.currentstyle[stylename]&nbsp;:&nbsp;
Document.defaultView.getComputedStyle (Obj,null). GetPropertyValue (StyleName); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &NBSP});&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp; element Drag plug-in &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$. Fn.dragdrop&nbsp;=&nbsp;function (options) &nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;var&nbsp;opts&nbsp;=&nbsp;$.extend ({},$.fn.dragdrop.defaults,options); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.each (function () {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//whether you are dragging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;bDraging&nbsp;=&nbsp;false;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Moving elements &NBSP;&NBSP;&NBSp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var
&nbsp;moveele&nbsp;=&nbsp;$ (this);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//click which element to trigger the move. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;//this element needs to be a child element of the moved element (such as a caption, etc.) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;focuele&nbsp;=&nbsp;opts.focuele&nbsp;?&nbsp;$ (
Opts.focuele,moveele) &nbsp;:&nbsp;moveEle&nbsp;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!focuele&nbsp;| | &nbsp;focuele.length&lt;=0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert (' focuEle&nbsp; is&nbsp;not&nbsp;found!&nbsp;the&nbsp;element&nbsp;must&nbsp;be&nbsp;a&nbsp;child&nbsp;of&nbsp; '
+this.id); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;
False &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;initdiffx| The distance between the mouse and the origin of the moved element when the y&nbsp;:&nbsp; is initially &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;movex| When y&nbsp;:&nbsp; move, the moved element locates position &nbsp; (new mouse position and initdiffx| Y's difference) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;//&nbsp; if a callback function in move is defined, the object will pass in the callback function as a parameter. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &NBSP;&NBSP;VAR&NBSP;DRAGPARAMS&NBSP;=&NBSP;{INITDIFFX: ', Initdiffy: ', MoveX: ', Movey: '};&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//are moved elements, you need to set the positioning style, otherwise the drag effect will not work. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;moveele.css ({' position ': ' absolute ', ' left ': ' 0 ', ' top ': ' 0 '}); When &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//clicks, record mouse position &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//dom Writing:&nbsp;
getElementById (' * * * '). Onmousedown=&nbsp;function (event); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;focuele.bind (' MouseDown ', function (e) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;//Mark starts moving &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdraging&nbsp;=&nbsp;true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;//Change Mouse Shape &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;MOVEELE.CSS ({' cursor ': ' Move '}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;//capture Events. (This usage, also has the advantage, is prevents the movement too quickly causes the mouse to run outside the moved element) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Moveele.get (0). setCapture) &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;moveele.get (0). SetCapture ();&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//(actually the distance of the mouse's current position relative to the origin of the moved element) &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;dom: (ev.clientx&nbsp;+&nbsp; Document.body.scrollleft&nbsp;-&nbsp;document.body.clientleft) &nbsp;-&nbsp;document.getelementbyid (' * * *).
Style.left; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragparams.initdiffx&nbsp;=&nbsp;$.mousecoords (E).
X&nbsp;-&nbsp;moveele.position (). Left; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Dragparams.initdiffy&nbsp;=&nbsp;$.mousecoords (E). Y&nbsp;-&nbsp;moveele.position (). Top; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Mobile Process &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;focuele.bind (' MouseMove ', function (e) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;if (bdraging) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the new position of the element being moved, in fact the difference between the current mouse position and the original position &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//actually, the new position of the moved element can also be directly the mouse position, which can also manifest drag, but the position of the element is not accurate. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Dragparams.movex&nbsp;=&nbsp;$.mousecoords (e) .x&nbsp;-&nbsp;dragparams.initdiffx; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;dragparams.movey&nbsp;=&nbsp;$.mousecoords (e) .y&nbsp;-&nbsp;dragparams.initdiffy; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;//whether to restrict movement in a region. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;moveele.css ({' Left ':d ragparams.movex, ' top ':
Dragparams.movey}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;else&nbsp;if&nbsp; (opts.dragdirection== ' vertical ') &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Moveele.css ({' Top ':d Ragparams.movey}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;if (opts.dragdirection== ' horizontal ') &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opts.callback.call (Opts.callback,dragparams); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//when mouse is bouncing, mark to cancel move &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;focuele.bind (' MouseUp ', function (e) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bDraging=false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;moveele.css ({' CUrsor ': ' Default '}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (MoveEle.get (0). releasecapture) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;moveele.get (0). ReleaseCapture (); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;}; &nbsp;&nbsp;&nbsp;&nbsp;//Default configuration &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$.fn.dragdrop.defaults&nbsp;= &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;focuEle:null,&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Click which element to start dragging, can be empty.
is not empty, a child element of the element being dragged is required. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;callback:null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;//the callback that is triggered when dragging. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragdirection: ' All ', &nbsp;&nbsp;&nbsp;&nbsp;//drag direction: [' All ', ' vertical ', ' horizontal '] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fixarea:null&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//restrict which area to drag and provide [Minx,maxx,miny,maxy] in array form &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;};
(jQuery);&nbsp;&nbsp;&nbsp;//&nbsp;test&nbsp; &nbsp;&nbsp;&nbsp;$ (function () {//qualified region, with callback function. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ (' #dragDiv '). DragDrop ({fixarea:[0,$ (' #dragContainer '). Width () -50,0,$ (' #dragContainer '). Height () -50],callback:function (params) {&nbsp;&nbsp;&nbsp;&nbsp;$ (' #span1 '). Text (' X: '
+params.movex+ ' &nbsp;y: ' +params.movey);
}}); Default Settings &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ (' #dragDiv1 '). DragDrop ();
}); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&nbsp;id= "Dragcontainer" &nbsp;style= "Position:relative;left :10px;top:10px;border:1px&nbsp;dashed&nbsp;blue;width:500px;height:500px; " &gt; &lt;div&nbsp;id= "dragdiv" &nbsp;style= "background-color:blue;height:50px;width:50px;" &gt; &lt;/div&gt; &lt;div&nbsp;id= "dragDiv1" &nbsp;style= "border:1px&nbsp;solid&nbsp;red;height:50px;width:50px;" &gt; &lt;/div&gt; &lt;/div&gt; &lt;span&nbsp;id= "Span1" &gt;&lt;/span&gt;&lt;/body&gt; &lt;/html&gt;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.