Drag the plugin draggable function is to drag the bound element, when the jquery UI plug-in and the element binding, you can invoke the draggable()
method to achieve the effects of various drag elements, the call format is as follows:
$(selector). draggable({options})
The options parameter is the configuration object at the time of the method invocation, and depending on the object you can set various drag effects, such as the "containment" property to specify the drag area, and the Axis property to set the coordinate direction when dragging.
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"> <Head> <title>Drag Plugin</title> <Linkhref= "Style.css"rel= "stylesheet"type= "Text/css" /> <Scriptsrc= "Http://www.imooc.com/data/jquery-1.8.2.min.js"type= "Text/javascript"></Script> <Scriptsrc= "Http://www.imooc.com/data/jquery-ui-1.9.2.min.js"type= "Text/javascript"></Script> </Head> <Body> <DivID= "Divtest"> <DivID= "X"class= "Drag">Drag along the x-axis</Div> <DivID= "Y"class= "Drag">Drag along the y-axis</Div> </Div> <Scripttype= "Text/javascript"> $(function () { $("#x"). Draggable ({containment:"Parent", Axis:"x"}) $("#y"). Draggable ({containment:"Parent", Axis:"y"}) }); </Script> </Body></HTML>
jquery Plugin (drag and drop)