What is the essence of Drag and Drop technology. Drag and drop elements (Drag and Drop)
Use of technology dragging (drag and Drop.) It gives the user to move various objects from one to another, for example, elements of one list to another. To do this, use two controls: receiver and source. The receiver is the object that an object will receive an object (moving object).
Events arising in the process of moving objects are listed in the order in which they arise.
OnStartDrag (TYTARDRAGEVENT TYPE) - At the beginning of the operation, the operation is generated by the source object. The parameters that are transmitted to the event handler: the Dragobject receiver object (TDRAGOBUCT type), the source object source (Togject Type).
Ondragover (TDRAGOVEREVENT TYPE) - Creates a receiver object when the object is moving above it. Parameters that are transmitted to event handler: Sender Object (Togject Type), Source Object Source (Type Type), State Status Statue (TDRAGState Type), X and Y (Integer Type) - Current Mouse Pointer Coordinates, Accept (BOOLEAN Type ) A sign of confirmation of the movement operation. The state of movement makes it possible to understand whether the moved object in the receiver area is moving in it, left it. The transmitted parameters enable the receiver object to accept or reject the source source. The ACCEPT parameter is set to TryE if the movement is accepted, otherwise False.
oNDRAGDROP (TDRAGDROPEVENT TYPEVENT) - is created by the receiver object when the moving object is lowered on it. The event handler is transmitted to the current coordinates of the mouse pointer, the Sender receiver object (Togject Type), the source object of movement SOURCE (TOBJECT TYPE).
onendDrag (type EndDRageVENT) - created when the drag and drop operation is completed. The event handler of the X and Y coordinate of the point where the SEnder source turned out to be the source and the Target receiver object.
To make drag and drop, it is enough to implement two events: ONDRAGDROP and ONDRAGOVER when the Dragmode property is installed equal to Dmautomatic. Otherwise, the start of the movement operation, the Begindrag method, it is necessary to encode the programmer.
To secure the material, create the following application. On the form of PANEL component. In the Dragmode property of the object inspector, set the DMAutomatic value. We highlight the object form and using the object inspector will create the following events:
Procedure TForm1.Formdragover (Sender, Source: Togject; X, Y: Integer; State: TDRAGSTATE; VAR Accept: Boolean); Begin IF Source \u003d Panel1 Then Accept: \u003d True ELSE Accept: \u003d false; end; Procedure TForm1.FormDragDrop (Sender, Source: Togject; X, Y: Integer); Begin panel1.left: \u003d x; Panel1.top:\u003d y; end;
Now running the application and pressing the mouse button on the panel, we can move the panel object across the form.
Outcome: We got acquainted with technology dragging (Drag and Drop) and used it in practice.
Methods of working with the technique of "Drag and Throw" were formed for many years. It is not surprising that with an increase in the number of programmers developing plug-ins with open source code (For example, for jQuery) old methods are reborn again. The JavaScript library is very adaptive and offers many improvements in our era of web technologies.
In this lesson, we will make a script that can be used to create dynamic rectangles with "Drops and throw" technique on your web site. The process is controlled by jQuery. Such scripts retain the time by providing ready-made functionality! And the library "Drag and throw" can be used in other projects.
Prepare content
First of all, we will prepare a small site for the project. In the project folder you need to create two catalog with remarkable names. "js" and "CSS" and empty file index.html . The code will be very simple to make a clear idea of \u200b\u200bwork, and a point appeared for further development.
Below is the code of our HTML file.. In chapter head. We turn on 3 scripts. The main script jQuery will be booked from the Google Code server. Our style.css styling file is also connected, which contains basic properties for forming external view Our document.
Drag me
I can also drag
P.S.: Can I quit anywhere!