JQuery list drag arrangement concrete implementation

  • 2020-03-26 23:05:29
  • OfStack

< img SRC = "border = 0 / / files.jb51.net/file_images/article/201311/201311041718413.gif? 201310417199 ">  

It's easy to implement this

First, import JS, jquery. Dragsort. JS, jquery. Dragsort -0.4.min. JS, jquery-1.4.2.min. JS.

Second, code
<h2> Drag and drop two sets of lists :</h2> 

<ul class="dragsort" id="list2" style="float:right;"> 

<ul class="dragsort" id="list1"> 

<!--  The sort is saved here to retrieve the return from the server  --> 
<input name="list1SortOrder" type="hidden" /> 

<script type="text/javascript"> 
$("#list1, #list2").dragsort({ 
dragSelector: "div", 
dragBetween: true, 
dragEnd: saveOrder, 
placeHolderTemplate: "<li class='placeHolder'><div></div></li>", 
scrollSpeed: 5 

function saveOrder() { 
var data = $("#list1 li").map(function(){ 

<style type="text/css"> 
.demo{padding:20px;width:800px;margin:20px auto;border:solid 1px black;} 
.demo h2{margin:30px 0 20px 0;color:#3366cc;} 
.dragfunction{margin:40px 0 0 0;} 
.dragfunction dt{height:30px;font-weight:800;} 
.dragfunction dd{line-height:22px;padding:0 0 20px 0;color:#5e5e5e;} 
.dragsort-ver li{height:30px;line-height:30px;} 
.dragsort li{float:left;padding:5px;width:100px;height:100px;} 
.dragsort div{width:90px;height:50px;border:solid 1px black;background-color:#E0E0E0;text-align:center;padding-top:40px;} 
.placeHolder div{background-color:white!important;border:dashed 1px gray!important;} 

Fourth, explain


Drag handles for list items of elements in the CSS selector. The default value is "li".

The dragSelector inside the element of the CSS selector does not trigger the dragsort. The default value is "input, textarea, a[href]".
The callback function that will be called when the drag is complete.
Set to "true" if you want to enable dragging the selected list between multiple lists. The default value is false.
Drag the HTML part of the list. The default value is "< Li> < / li>" .
CSS selector element as a scrolling container, such as overflow of divs set to automatic. The default value is "window".
A number which represents the speed, when the page drags a certain item, will scroll outside the container, the higher the use value is the speed and the lower the value is the slower. If set to "0" to disable scrolling. The default value is "5".

Related articles: