JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<div class="demo">
<ul id="sortable" class="ui-sortable">
<li class="ui-state-default" style="">0</li>
<li class="ui-state-default" style="">1</li>
<li class="ui-state-default" style="">2</li>
<li class="ui-state-default" style="">3</li>
<li class="ui-state-default" style="">4</li>
<li class="ui-state-default" style="">5</li>
<li class="ui-state-default" style="">6</li>
</ul>
</div>
CSS
<style type="text/css">
body {
text-align: center
}
.demo {
width: 580px;
margin: 0 auto;
text-align: left
}
#sortable {
list-style-type: none;
margin: 0;
padding: 0;
width: 60%;
}
#sortable li {
margin: 0 3px 3px 3px;
padding: 0.4em;
padding-left: 1.5em;
font-size: 1.4em;
height: 18px;
}
#sortable li span {
position: absolute;
margin-left: -1.3em;
}
#sortable li.highlights {
background: yellow
}
</style>
JavaScript
$(function() {
$('#sortable').sortable({
start : function(event, ui) {
var start_pos = ui.item.index();
ui.item.data('start_pos', start_pos);
},
update : function(event, ui) {
var index = ui.item.index();
var start_pos = ui.item.data('start_pos');
//update the html of the moved item to the current index
$('#sortable li:nth-child(' + (index + 1) + ')').html(index);
if (start_pos < index) {
//update the items before the re-ordered item
for(var i=index; i > 0; i--){
$('#sortable li:nth-child(' + i + ')').html(i - 1);
}
}else {
//update the items after the re-ordered item
for(var i=index+2;i <= $("#sortable li").length; i++){
$('#sortable li:nth-child(' + i + ')').html(i-1);
}
}
},
axis : 'y'
});
});