Although sorting can be achieved by moving elements up and down, it is not flexible enough and rigid, and cannot quickly achieve the purpose of sorting we want. Below we explain how to quickly drag and drop to the sorting position you want.
First of all, we need to introduce a plug-in gridly.js to implement element dragging.
The following simple lines of js code can achieve the functions we want:
( dom='' ( i = 0; i <= 10; i++(i%2!=0+=''+i+'
'+=''+i+'
''.gridly')[0]).append(dom); reordering = reordered = arrdom= array=[]; $.each(arrdom,'.gridly' $('.gridly'100, gutter: 20, columns: 7
The effect is as shown below:
Explanation below: This plug-in is very simple and easy to use. When we find that setting the number of columns to display and the line spacing has no effect, we might as well open the gridly.js source code, find the following method, and set it up.
Related recommendations:
jQuery drag sorting plug-in to create drag sorting effect (with source code download)_jquery
Jquery drag and drop sorting simple implementation method (enhanced version)_jquery
The above is the detailed content of jQuery code to implement free dragging and sorting of elements. For more information, please follow other related articles on the PHP Chinese website!