Jquery-ui implement the control drag in the folding panel

Source: Internet
Author: User

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><Metacharset="Utf-8"/><Title> dragging elements from the folding panel</Title><ScriptSrc=".. /jquery/jquery-1.11.2.min.js "></Script><ScriptSrc=".. /jquery/jquery-ui.min.js "></Script><Linkhref=".. /jquery/jquery-ui.min.css "Rel="Stylesheet" ></Link><Style>#accordion{Width20em;}. Accordion-button{WidthAutoHeightAutoMargin-left:1em;}. graggable{}</Style></Head><Body><DivId="Accordion" ><H3><Ahref="#" > button</A></H3><Div><buttonId="Button1"class="Accordion-button" >button1</Button><buttonId="Button2"class="Accordion-button" >button2</Button></Div></Div></Body></Html><Script>Element EventChange,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 ();Changes the button2 to a draggable element and tests that it can only be dragged within the collapsed panel by dragging the $ ("#button2"). Draggable ({cancel:". Title"});Create a control to drag on the Button1 first AddElement ($ ("#button1"));Add an X controlfunctionAddElement(x) {Build a new control on top of an existing controlvar classattr ="Accordion-button graggable";Get element contentvar text = X.text ();Element CSS style, mainly set to the same position as the original elementvar styleattr =' style= ' position:absolute;top: ' + x.position (). Top +' Px;left: ' + x.position (). left+' px; ';Set element $elem = <button ' +styleattr+ ' class= "' +classattr+" +text+ </button> ‘; $ (//add element $ (//set element $ (//set element can drag //Register mouse Bounce event for all controls, generate a new current control every time it is bounced $ ( "MouseUp",  function () {addelement (x);})} </SCRIPT>         

Implementation results:

Jquery-ui implement the control drag in the folding panel

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.