Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drag event for jquery-ui-sortable

How to listen to drag event when a jquery-ui-sortable is being dragged?

By hit-n-trial strategy, I've tried drag event from jquery-ui-draggable but it's not working.

$('.widget_container').sortable({
    drag: function(event, ui) { console.log('drag'); }
});
like image 755
Imran Naqvi Avatar asked Nov 16 '11 07:11

Imran Naqvi


People also ask

How to use jQueryUI sortable?

By default its value is "input,textarea,button,select,option". This option is a selector that identifies another sortable element that can accept items from this sortable. This allows items from one list to be moved to other lists, a frequent and useful user interaction. If omitted, no other element is connected.

How do you drag and drop in jQuery?

Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .

How does jQueryUI draggable work?

jQueryUI provides draggable() method to make any DOM element draggable. Once the element is draggable, you can move that element by clicking on it with the mouse and dragging it anywhere within the viewport.

Why is draggable not working?

You have one of these problems: Your jQuery or jQuery UI Javascript path files are wrong. Your jQuery UI does not include draggable. Your jQuery or jQuery UI Javascript files are corrupted.


1 Answers

Use sort event for this purpose:

$(".sortable").sortable({
    sort: function(e) {
      console.log('X:' + e.screenX, 'Y:' + e.screenY);
    }
});

http://jsbin.com/kegeb

like image 169
v42 Avatar answered Sep 24 '22 08:09

v42