I have the following code, which allows user to drag and drop from one list to another. Now, how can I allow the user to select and drag & drop multiple items?
Something like this?
http://jsfiddle.net/T68Fn/
I have tried to incorporate the code from the jsfiddle in, but can't really get it to work. Any help is highly appreciated.
Please help me out. Thank you very much.
HTML
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
</head>
<body>
<div id="maincontainer">
<div id="navtoplistline"> </div>
<div id="contentwrapper">
<div id="maincolumn">
<div class="text">
<hr />
<div class="listBlock">
<h2>Available</h2>
<ul id="sortable1" class='droptrue'>
<li class="ui-state-default" id="article_1">Article #1</li>
<li class="ui-state-default" id="article_2">Article #2</li>
<li class="ui-state-default" id="article_3">Article #3</li>
</ul>
</div>
<div class="listBlock">
<h2>My Articles</h2>
<ul id="sortable2" class='droptrue'></ul>
</div>
<br clear="both" />
<p>Which articles, in which order?:
<br />
<input type="text" id="postOrder" name="postOrder" value="" size="30" />
</p>
</div>
</div>
</div>
</div>
</body>
</html>
CSS
.listBlock {
float: left;
}
#sortable1, #sortable2 {
list-style-type: none;
margin: 0;
padding: 0;
margin-right: 100px;
background: #eee;
padding: 5px;
width: 300px;
border: 1px solid black;
}
#sortable1 li, #sortable2 li {
cursor: move;
margin: 5px;
padding: 5px;
font-size: 1.2em;
width: 250px;
background: none;
background-color: white;
}
SCRIPT
$(function() {
$("ul.droptrue").sortable({
connectWith: 'ul',
opacity: 0.6,
update : updatePostOrder
});
$("#sortable1, #sortable2").disableSelection();
$("#sortable1, #sortable2").css('minHeight',$("#sortable1").height()+"px");
updatePostOrder();
});
function updatePostOrder() {
var arr = [];
$("#sortable2 li").each(function(){
arr.push($(this).attr('id'));
});
$('#postOrder').val(arr.join(','));
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…