Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make jQuery UI sortable divs dragged only from an icon?

I've used some jQuery UI sortable plugins but I always found the same problem, I can't select or click inside the sortable DIVs, So, maybe I can find the solution by putting an icon from where you only can drag the div so you can be able to select the other part.

How to do that?

like image 529
CodeOverload Avatar asked Apr 23 '10 01:04

CodeOverload


2 Answers

In each of your sortable items, include whatever you'd like as your handle. (IE, an img or a styled span.) Give the handle element(s) a class name — handle might be a good choice.

In your sortable constructor, set the handle selector to the class you've given to your handles.

$('#div').sortable({
    handle: '.handle',
    cursor: 'move',
    ...
});

I'd also recommend giving your handle element a style of .handle { cursor:move; } so the user has some indication that grabbing it will allow them to move the item around.

like image 91
josh3736 Avatar answered Sep 24 '22 11:09

josh3736


The draggable handle.

like image 41
wombleton Avatar answered Sep 25 '22 11:09

wombleton