It's easier to take something and put it than to write what you need to take and where to put it. Of course, without a mouse, or a similar device, you can’t select or specify anything, but even in the current state of things, using the drag and drop idea is very natural and comfortable.
The scope of the idea is not only online stores, digital libraries, search or Information Systems, but also the applied area. The idea is very applicable in the development of sites and their elements, created and maintained interactively, without the participation of a programmer.
Description of the idea
Select, move and put - the idea is natural and convenient. It is simply amazing that it was not born when the mouse became an indispensable accessory for the computer.
The most obvious example is choosing a product in an online store. Select the desired product with the mouse and drag it to the shopping cart - simply, naturally and conveniently. File Upload: Taking a document outside of the browser window and placing it on a page element, thus initiating the transfer of the document to the server, is also a practical idea.
For the developer, the idea of "drag and drop" is the manipulation of page elements without manually recalculating the coordinates and sizes of tags, the ability to select multiple elements and align them, and move the sides of block tags.
HTML and CSS - great languages descriptions of tags and their design styles, but when a developer has the ability to interactively manipulate page elements without manually recalculating coordinates and sizes, this makes the work more comfortable and efficient.
Easy file transfer
"Drag and drop": translation from English into Russian literally sounds like "drag and drop." In practice, it sounds and works better: chose, transferred and let go - simply and naturally.
Implementing file transfers on a page to a page, to a server, or for other use is very simple.
In this example, several files on the desktop were selected with the mouse (left figure). On the selection, the left mouse button was pressed and the selected "went" to the basket. The browser itself showed how this happens, wrote a “copy” hint and created the outlines of the files being moved around.
When the mouse was over the basket, the visitor released the left mouse button, the drag and drop event took place and on the site page (bottom image), the JavaScript code was able to receive and process all the files that the visitor provided to the page (site).
Implementation Description
The code that performs this procedure is very simple. Even a novice developer can repeat it in any use cases.
Here, the user interface is represented by two tags: scPlaceFile (this is the basket itself where you want to put files) and scPlaceFiles (this is the result of processing files, in this case a list of them).
The logic of the page is as follows. When the page is loaded in the browser, the "ondrop" event handler is assigned in the basket - put, the rest of the events are blocked and not used.
The page works normally, but as soon as the visitor selects the file (files) and drags them to the basket image, that is, to the scPlaceFile tag, the “files have arrived” event will be processed.
This handler simply displays a list of files. Their number is in event.dataTransfer.files.length, and information about each file is in event.dataTransfer.files[i].name. What to do with the received data is determined by the developer, in this case, a list of received files is simply formed.
Once processed, the event is blocked and not propagated. This is necessary so that the browser does not engage in amateur activities and does not interfere with the processing of the information received.
DnD and external data
Uploading images to the server in "drag and drop" is a common practice in this technology. Typically, a developer creates a file upload form (1) that works in the usual way (2). The visitor can normal mode select files and upload them.
However, if a visitor drags and drops to a certain place in the form, then the file name field (files) will be filled in automatically.
This good decision. It is, of course, very difficult to admit that there is no mouse on the computer. But it is better to develop the user interface in the usual way and in the DnD implementation.
DnD and internal data
Taking care of the interests of the visitor is always important, but the concerns of the developer also matter. You can implement "drag and drop" not only by standard means, but also by handling mouse events on page elements.
The task of calculating tag coordinate values and their sizes arises constantly. Manual calculation is good practice, but the interactive option is more convenient. All tags are always rectangular in shape, and by monitoring mouse events on the sides of elements, you can create the ability to automatically move elements to the right place on the page, or change them.
Handling the mouse button click event - remembering the coordinates of the click location, for example, one of the sides of the element. Move the mouse - the side moves in the desired direction. Releasing the mouse button - the side stops and its coordinates change. This way you can change the position of the element or its size.
It's not formally drag and drop, but the effect is similar and practical. By making universal handlers for any page element, you can get a good interactive result, speed up development and simplify the code.
Visual and manual programming
A mouse on a computer and fingers on a smartphone are completely different approaches to the implementation of the user interface (visitor, developer). It is a completely natural and modern requirement for cross-browser compatibility.
All this together makes it difficult to create pages, but applying the idea of \u200b\u200bdrag and drop in it standard form, using its events, combining this idea with the usual events on elements, you can implement a mechanism in which the creation of the page will occur visually.
Now let's look at the selection of an element or elements. Selection fact - the appearance of a context menu, for example, the goal is to align the selected one (left, right, center), or distribute elements vertically or horizontally with the same step, or change their size (minimum, maximum).
Automatic recalculation of coordinates and dimensions is preferable to manual. Fewer mistakes - the goal is reached faster. In addition, you can make a page in one browser, save the position and size of elements. By opening this page on a smartphone, you can correct the coordinates and dimensions and remember them for specific model smartphone or browser version.
So the same page without manual compliance with the cross-browser compatibility requirement will have different data to display on various devices and in different browsers.
If you allow the visitor to perform these procedures on their own, as well as select the necessary page elements from among those provided by the developer, it is possible to ensure cross-browser compatibility and the required functionality of the page, taking into account the user's opinion.
The Drag and Drop feature can help boost your iPad's performance. Here's how you can use it.
So you can move a file from one cloud storage service to another, copy text from Safari into a text editing app to add a quote or create backup certain photos in the file storage application.
How to drag and drop photos, files and text
1. Touch and hold the photo, file, or highlighted text you want to drag to another app.
2. Drag the element to the desired location in this application or another that you have open in Slide Over or Split View and release.
How to drag and drop multiple photos or files at once
1. Touch and hold one of the photos or files you want to drag.
2. While dragging the current item, tap another photo or file that you also want to drag. Do it again with as many elements as you want to move.
3. Drag all selected objects to the designated place in another application that you have open in Slide Over or Split View and release them.
How to drag text from one application to another
1. Tap and hold on the part of the text you want to drag to select it.
2. Use selection points to highlight the rest of the text you want to drag.
3. Press and hold the selected text.
4. Drag the text to the application where you want to place it and release it.
How to change the position of icons of several applications at once using "Drag and Drop"
While most iOS drag and drop functionality only works on the iPad, this trick actually works on both the iPhone and iPad. This allows you to organize the location of applications on the home screen using « Drag and Drop" instead of moving them one by one.
1. Touch and hold the icon for the app you want to reposition on the home screen.
2. Tap additional apps that you also want to move.
3. Drag these apps to the page or folder where you want them to be and drop them.
182
In this example, we select a div element and make it moveable by calling on it draggable() method. As shown in the figure below, in the opened document, the element takes its usual position, but after that it can be moved with the mouse pointer to any place in the browser window:
The drag and drop feature is useful on its own, but it's even more useful when used in conjunction with the Droppable interaction, which is described next.
Draggable interaction is implemented solely through the use of specific HTML markup and CSS styles. This means that this functionality will work in almost any browser, but elements endowed with it will not be able to work with similar native drag-and-drop facilities. operating systems.
Drag-and-drop operations defined by the HTML5 specification are usually implemented using native operating system mechanisms. If you're using the jQuery UI drag-and-drop mechanism, it's best to disable the HTML5 equivalents to avoid conflicts. To do this, set the draggable attribute of the document's body element to false.
Customizing Draggable Interaction
There are many customization options for Draggable interaction. The most important properties covered in the following sections are summarized in the table below:
Property | Description |
---|---|
axis | Restricts movement to certain directions. The default value is false, which means no restrictions, but you can also specify the value "x" (move only along the x-axis) or "y" (move only along the y-axis) |
containment | Restricts the location of the floating element to a specific area of the screen. Supported value types are described in the table below, with the corresponding example. The default value is false, it means no restrictions |
delay | Specifies the amount of time an element must be dragged before it moves. The default value is 0, which means no delay |
distance | Specifies the distance the user must drag an element from its starting position before it actually moves. The default value is 1 pixel |
grid | Forces binding of the moved element to the grid cells. The default value is false, which means no binding |
Restriction of directions of movement
There are several ways in which you can restrict the movement of an element to certain directions. The first of these is to use the axis option, which allows you to limit the direction of movement to the X or Y axis. An example is shown below:
...