I have a sortable div (#sortable
) with elements (.draggable
) inside it. In there, when I sort elements from bottom to up, the elements can easily be sorted by dragging up and I don't have to drag much to the top. But when sorting elements from up to bottom, I have to drag the element far below then wanted. Is there any way to control the sorting of elements, so that even if I drag just a little bit up/below and not all the way up/down it will display the placeholder to place the element respectively?
Demo at codepen.
js
$('#content #sortable').sortable({
handle: '.drag_handle',
placeholder: "ui-state-highlight",
axis: "y"
});
$('#blocks .draggable').draggable({
helper: "clone",
revert: "invalid",
connectToSortable: '#content #sortable'
});
update
Sorting upwards
Sorting upwards is easy as I don't have to drag the element all the way up above the element I want to sort with.
Sorting downwards
Sorting downwards is difficult as I have to drag the element all the way down below the element I want to sort with.
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.
jQueryUI provides sortable() method to reorder elements in list or grid using the mouse. This method performs sortability action based upon an operation string passed as the first parameter.
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 .
Just change the tolerance
option of the sortable API to "pointer"
. This option will make the draggable considered to be on the placeholder when the cursor is over it (what you need right now) instead of wait until over 50% of the element is overlapping the placeholder. This was why you had to scroll way too far down in order to sort it.
$('#content #sortable').sortable({
handle: '.drag_handle',
placeholder: "ui-state-highlight",
tolerance: "pointer"
});
Here is the updated CodePen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With