Maybe this is not the best way, but in the documentation has the reference of sortable
https://api.jqueryui.com/sortable/#Event-Activate
It would be something like: $( ".selector" ).on( "sortactivate", function( event, ui ) {} );
But I did taking the auxiliary class helper by CSS
Note that you do not apply the class in click
only in the drag
What I’ve done is that when the element is in the state sortable
the jquery.ui
applies a class to it called ui-sortable-helper
, I went to CSS and put a style in this class and it worked as I wanted
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Sortable - Connect lists</title>
<!-- <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> -->
<style>
#sortable1,
#sortable2 {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#sortable1 li,
#sortable2 li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
.ui-sortable-helper {
background-color: red;
transform: scale(0.7)
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function() {
$("#sortable1").sortable()
})
</script>
</head>
<body>
<ul id="sortable1">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
</body>
</html>
Search by draggable, ondragend, ondragstart, ondrag, ondragenter, ondragleave and similar. The first time I implemented it took a little work, in the following times was already more of good.
– Leonardo Getulio