Because a project needs to be implemented in the front-end interface to drag the control into the workspace of the function (similar to Android and MFC visual Interface development), so began to learn the powerful jquery, found inside the Jquery-ui have folding panels, buttons and other controls, However, when you drag a button in the Collapse Panel, the button's drag range can only be inside the collapsed panel and cannot be dragged to the workspace. So here's a bit of a bend:
The main implementation of the process is: first in the control indicates that a copy is generated, each time the control is dragged by the copy, when the drag is completed, that is, after the mouse bounces, the original control surface is generated a copy to be dragged next time. (Some other details were written in the comments.)
Code:
<! DOCTYPE html><html><head><meta charset="Utf-8" /><title>Drag elements from the folding panel</title><script src=".. /jquery/jquery-1.11.2.min.js "></script><script src=".. /jquery/jquery-ui.min.js "></script><link href="... /jquery/jquery-ui.min.css " rel=" stylesheet "></link><style> #accordion{ width:em;} . Accordion-button { width:auto; height:auto; margin-left:1em; }. graggable{} </style></head><body><div id="accordion"><h3><a href="#">Button</a></h3><div><button id="Button1" class="Accordion-button">Button1</button><button id="Button2" class="Accordion-button"> Button2</button></div></div></body></html><script>//Element Events//change,click,dblclick,error,focus,focusin,focusout,keydown,keypress,keyup,//mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,resize,scroll,select,submit,unload $("#button1"). button (); $ ("#button2"). button (); $ ("#accordion"). accordion ();//Change the button2 to a draggable element and test that it can only be dragged inside the collapsed panel$("#button2"). Draggable ({cancel:". Title"});//Create a control to be dragged on the Button1 firstAddElement ($ ("#button1"));//Add an X control function addelement(x){ //Create a new control on top of an existing control varclassattr ="Accordion-button graggable";//Get element content varText = X.text ();//element CSS style, mainly set the same position as the original element varStyleattr =' style= ' position:absolute;top: '+ x.position (). Top +' Px;left: '+ x.position (). left+' px; ';//Set element$elem =' <button '+styleattr+' class= '+classattr+' "role=" button "> "+"'+text+' </button> '; $(' body '). append ($elem);//Add element$(". Graggable"). button ();//Set element$(". Graggable"). Draggable ({cancel:". Title"});//Set element to drag //Register mouse bounce events for all controls, generate a new current control each time it bounces$(". Graggable"). On ("MouseUp", function(){AddElement (x); })}</script>
Implementation results:
JQuery BASIC Programming Jquery-ui implement the control drag in the collapsed panel