agis
agis

Reputation: 1841

jQuery UI sortable - do something when item is dragged

I have two block one is "draggable" and the other is "sortable".

What I want to do is when I start dragging an item from "sortable" to do something via jQuery.

Here's my JS:

 $(".sortableList").sortable({

 });
 $(".draggable").draggable({
  connectToSortable: '.sortableList',
  cursor: 'pointer',
  helper: 'clone',
  revert: 'invalid',
  start: function (event, ui) {
     $(this).addClass('testing');
 }
 });

Here's a jsbin

Any ideas how can I do this?

Upvotes: 1

Views: 133

Answers (1)

Giannis Grivas
Giannis Grivas

Reputation: 3412

You have to add update event at sortable like this :

     $(".sortableList").sortable({ 
            update: function(event, ui) {
               //alert("Do something here when item left!");
            },
            start: function(event, ui) {
               //alert("Do something here when item just dragged from sortable!");
        },
     });

So when the dragged from sortable is left to the position update event will trigger and when it dragged .start is triggered.

Upvotes: 3

Related Questions