JSFiddle - React, Tailwind, and code Playground

by Dhanck

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<body>

<ul id="sortable" class="connectedSortable">
	<li id="li1"><div>1- First</div></li>
	<li id="li2"><div>2- Second</div></li>
	<li id="li3"><div>3- Third</div></li>
	<li id="li4"><div>4- Fourth</div></li>
	<li id="li5"><div>5- Fifth</div></li>
	<li id="li6"><div>6- Sixth</div></li>
	<li id="li7"><div>7- Seventh</div></li>
	<li id="li8"><div>8- Eighth</div></li>
  <li id="li1"><div>1- First</div></li>
	<li id="li2"><div>2- Second</div></li>
	<li id="li3"><div>3- Third</div></li>
	<li id="li4"><div>4- Fourth</div></li>
	<li id="li5"><div>5- Fifth</div></li>
	<li id="li6"><div>6- Sixth</div></li>
	<li id="li7"><div>7- Seventh</div></li>
	<li id="li8"><div>8- Eighth</div></li>
</ul>
<!--    
<ul id="album2" class="connectedSortable">
	<li id="li1"><div>1- 1</div></li>
	<li id="li2"><div>2- 2</div></li>
	<li id="li3"><div>3- 3</div></li>
	<li id="li4"><div>4- 4</div></li>
	<li id="li5"><div>5- 5</div></li>
	<li id="li6"><div>6- 6</div></li>
	<li id="li7"><div>7- 7</div></li>
	<li id="li8"><div>8- 8</div></li>
</ul>
<div id="anotheralbum" class="connectedSortable">
another album - no style for the lists inside here
</div>
    -->
<br style="clear:both">
<br>
<br>

 
 
</body>

CSS

*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html, body{
  margin:0;
  padding:0;
}
#sortable {
	list-style: none;
	float: left;
	width: 100%;
  height:100vh;
  margin:0;
}
#sortable li  {
	float: left;
	margin: 5px;
}
#sortable div {
	width: 100px;
	height: 100px;
	border: 1px solid #CCC;

	background: #F6F6F6;	
}
#sortable .ui-sortable-placeholder {
	border: 1px dashed #CCC;
	width: 100px;
	height: 100px;
	background: none;
	visibility: visible !important;
}
#sortable .ui-selecting div, 
#sortable .ui-selected div {
	background-color: #3C6;
}
#anotheralbum {
    list-style: none;
	float: left;
	width: 20%;
    height: 800px;
	border: 1px solid green;
}

JavaScript

$(function() {
//

$('body').click().selectable({
	filter: 'li'
    //filter: '#album2 > li'
});

/*
Since the sortable seems unable to move more than one object at a 
time, we'll do this:

The LIs should act only as wrappers for DIVs.

When sorting a LI, move all the DIVs that are children of selected 
LIs to inside the sorting LI (this will make them move together);
but before doing that, save inside the DIVs a reference to their
respective original parents, so we can restore them later.

When the user drop the sorting, restore the DIVs to their original
parent LIs and place those LIs right after the just-dropped LI.

Voilá!

Tip: doesn't work so great if you try to stick the LIs inside the LI
*/

$('#sortable').sortable({
	delay: 100,
	start: function(e, ui) {
		var topleft = 0;
		
		// if the current sorting LI is not selected, select
		$(ui.item).addClass('ui-selected');
		
		$('.ui-selected div').each(function() {

			// save reference to original parent
			var originalParent = $(this).parent()[0];
			$(this).data('origin', originalParent);
			
			// position each DIV in cascade
			$(this).css('position', 'absolute');
			$(this).css('top', topleft);
			$(this).css('left', topleft);
			topleft += 20;

		}).appendTo(ui.item); // glue them all inside current sorting LI

	},
	stop: function(e, ui) {
		$(ui.item).children().each(function() {
			
			// restore all the DIVs in the sorting LI to their original parents
			var originalParent = $(this).data('origin');
			$(this).appendTo(originalParent);

			// remove the cascade positioning
			$(this).css('position', '');
			$(this).css('top', '');
			$(this).css('left', '');
		});
		
		// put the selected LIs after the just-dropped sorting LI
		$('#sortable .ui-selected').insertAfter(ui.item);
        
        // put the selected LIs after the just-dropped sorting LI
		$('#album2 .ui-selected').insertAfter(ui.item);
	}
});




//
});