Menu
Is free
check in
the main  /  the Internet / What is the essence of Drag and Drop technology. Drag and drop elements (Drag and Drop)

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

Yes Yes. It is me.

I can also drag

(Zindex: 200, Opacity: .9)

P.S.: Can I quit anywhere!

Inside section body. only two blocks are placed divwhich contain both rectangles. The code is quite simple and understandable. Inside each rectangle placed headers with classes handler and handler2.. This is important, since when dragging each rectangle behaves in its own way.


Install CSS.

HTML code is very simple. If the main markings are clear to you, then styles CSS. Also will not represent difficulties. Basically, fields, indents and colors are determined.

Body, HTML (Font-Family: Calibri, Sans-Serif; Background: # EAF3FB; font-size: 12px; Height: 1000px; Line-Height: 18px;) P (Height: 30px;)

Selectors body, HTML. Used only for a demonstration page. And the entire content is located in two dragging rectangles.

Dv1 (width: 200px; background-color: # EFF7FF; Border: 1px Solid # 96C2F1; Position: absolute; left: 100px; top: 100px;) .dv1 h2 (background-color: # B2D3F5; padding: 5px; font- Family: Georgia, "Times New Roman", Times, Serif; Font-Size: 1.0EM; text-transform: uppercase; Font-Weight: Bold; Color: # 3A424A; Margin: 1px; Cursor: Move;) .dv1 div (Padding: 5px; margin-bottom: 10px;) .dv2 (background-color: # F7EBFB; Border: 1px Solid # A36FDE; Width: 550px; Position: absolute; cursor: move; left: 400px; top: 230px;) .DV2 H2 (Background-color: # EACFE9; letter-space: -0.09em; font-size: 1.8em; font-weight: bold; padding: 15px; margin: 1px; color: # 241F24; Cursor: Move;) .dv2 .content2 (Padding: 5px; Margin-Bottom: 10px;)

For both classes.dv1 i.dv2, we use absolute positioning. This is not necessary and probably it is not the most the best way To position the drag-free rectangles. However, for our example, such positioning makes sense, since each time the page rectangles are installed in certain places.

Also fonts and colors differ for rectangles to make it easier to see the difference.

The rest of the headers and the content of the blocks is almost identical. If you copy styles in your project, change the names before running. In some cases, it will be more logical to use ID instead of classes, for example, when using the "Drag and throw" techniques for one particular block.

We disassemble javascript

Two JavaScript files contain all the code you need. We lower the details of the job with jQuery, as it goes beyond the lesson. Pay attention to the jquery.dragnndrop.js file.

The function is determined on line 22 Drags..

$ .fn.drags \u003d Function (OPTS) (VAR PS \u003d $ .extend (Zindex: 20, Opacity: .7, Handler: NULL, OnMove: Function () (), OnDrop: Function () ()), Opts );

Here the returned variable and initialization data is set for Drags.. This method is very widely used when working with jQuery to transfer options to other functions. Inside, we set the variables for all available options for dragging rectangles.


The next part of the code includes event handlers for variable dragndrop.. Both events drag. and drop. Call functions with the transfer of event parameters in them. These events occur when you click the mouse button to drag the object, and then release it.

VAR DRAGNDROP \u003d (DRAGDATA \u003d E.DATA.DRAGDATA; DRAGDATA.Target.css ((Left: Dragdata.left + E.pagex - Dragdata.Offleft, Top: Dragdata.top + E.pagey - dragdata.offtop)); dragdata.handler.css ((Cursor: "Move")); dragdata.target.css ((Cursor: "Move")); dragdata.ONMOVE (E);), Drop: FUNCTION ( e) (var dragdata \u003d e.data.dragdata; dragdata.target.css (dragdata.oldcss); //. CSS (("OPACITY": "")); dragdata.handler.css ("Cursor", Dragdata. oldcss.cursor); dragdata.ondrop (E); $ (). Unbind ("Mousemove", dragndrop.drag) .Unbind ("MouseUp", dragndrop.drop);))

Our functions manipulate CSS positioning each object. If you change the absolute positioning of your objects, it will not affect the operation of the code, since each JavaScript function changes any style that is defined for the object.

The remainder code is checked for handler and cosmetic changes from other styles. Here you can add a change in transparency, font and its colors, or add new paragraphs.

Drag / Drop functions

The second FN.JS file contains a simple code. We wait for the full download of the document, after which we call our functions. Two instances of the function are determined Drags.which was understood earlier.

We have two moved blocks with classes.dv1 i.dv2. If you need to leave one moving block, you just need to remove the second part of the code. Adding another moved block is also simply carried out. You only need to add new feature In this file.

First of all, you need to set options when calling a function. Be sure to set the name of the handler. With it, we inform jQuery, which handler is used when you press the mouse button in a specific document area. The name of the handler may be a class or an ID attribute.

In our first function there are two event handler onmove. and ondrop.. Both call new features transmitted to the current event as variables. Here is the manipulation of the HTML code in the rectangle to upgrade with each movement. This is a wonderful effect to demonstrate how it is possible to control the process using simple jQuery events.

In the second function, we use the parameters Z-Index and Opacity. Can I add other CSS properties? But this will require a reworking JavaScript code to check the installations. For example, you can transmit another font style or meaning for height and width for a rectangle moving - it will be a very interesting trick!

Conclusion

As a result of a small work, we received at our disposal a wonderful interface with the function "Drops and throw". JQuery provides huge benefits for developers who crave old methods to use old methods.

As a result, we received not only the functions of event handlers, but we can transmit new variables into drag-free blocks. This opens up new opportunities for creativity. The demonstration to the lesson contains only the sketch of what can be done with the help of such a code.

So learn the jQuery documentation to use library functions.

Where the GUI elements are implemented using a pseudographic) using the Mouse Manipulator or Touchscreen.

The method is implemented by "capture" (by pressing the main one ( first, more often than the left) mouse button) displayed on the computer's computer screen, software available for such an operation, and move it to another place (to change the location) or "throwing" it to another element (to call the appropriate provided by the program, actions). In relation to the windows (also capable of moving in this method), this term is usually not used.

Basic actions and the most simple examples Drag-and-drop actions are: Moving an object, move the object in from the panel to the panel, although in modern operating systems Drag-and-Drop got widespread use and is one of the main ways to interact with the computer in the graphical user interface.

Objects for moving can be the following interface elements: Desktop icons (icons), Floating toolbar, program shortcuts in the taskbar (starting with Win XP), TreeView elements, text string, DataGridView cell., Also OLE elements. Objects can move both within a certain area, within one window, between the panels of one window and between different windows.

Dragging event must be initiated by any user action. Most often, this action is to press the left mouse button on the element (the event is called Moudown), which can be moved in its container. Some components possess own events The start of the DRAG-N-DROP - for example, TreeView has an ITEMDRAG event.


Wikimedia Foundation. 2010.

Watch what is "DRAG-AND-DROP" in other dictionaries:

    Drag and Drop. - \u003c[Dræg ənd DRɔ̣P] N.; ; unz.; Edv\u003e Das Anklicken Eines Objektes, Das Auf Dem ComputerBildschirm (in Eine Andere Datei Bzw. An Eine Andere Stelle) Verschoben U. Dort Wieder Losgelassen Wird [ENGL. Drag "Ziehen" + and "und" + drop "Fallen ... Universal-Lexikon

    Form of performing any actions in graphic interfaces User implying use computer mouse. Translated from English means literally: Turning and throwing. The action is performed by operating visible on the screen ... ... Business Terms Dictionary

    drag and Drop. - (Computing) to Move An Icon, File, etc Across The Screen using a Mouse and Release It in a Different Place (Drag and Drop Adjective) Main Entry: Drag ... Useful English Dictionary

    drag and Drop. - IT to Move Something From One Area of \u200b\u200bA Computer Screen to Another using the Mouse: »The Software Allows You to Drag and Drop Elements for the the Anywhere You Want. Main Entry: Drag ... FINANCIAL AND BUSINESS TERMS

    dRAG-AND-DROP - UK US VERB N.; Gen:; PL.: UNZ.; Edv\u003e Das Anklicken Eines Objektes, Das Auf Dem ComputerBildschirm (in Eine Andere Datei Bzw. An Eine Andere Stelle) Verschoben U. Dort Wieder Losgelassen Wird)