I currently have a simple draggable list, which I want to be inside a div ( the items ) and scrollable.
$( ".draggable" ).draggable();
I currently have this fiddle: http://jsfiddle.net/YvJhE/660/
But as you can see, the draggable elements stay inside the elements container, I want them to be able to drag out, but also the ability to scroll inside the elements container as soon as there are more elements, than the container long is.
Can anyone get me on the right track?
In this article, we learnt about the jQuery UI draggable functionality which basically allows the DOM elements to be moved or dragged using the mouse. This is done by clicking on the object to be dragged using mouse and dragging it anywhere within the view port.
Allow elements to be moved using the mouse. Enable draggable functionality on any DOM element. Move the draggable object by clicking on it with the mouse and dragging it anywhere within the viewport. Want to learn more about the draggable interaction? Check out the API documentation.
Enable draggable functionality on any DOM element. Move the draggable object by clicking on it with the mouse and dragging it anywhere within the viewport.
jQueryUIdraggable () method allows the DOM elements to be moved using the mouse. This method can be used to drag the DOM elements anywhere within the view port by clicking on the object using mouse and then dragging it to anywhere you want to within the view port.
jQuery handles interactions like these with a helper object that you can append to another DOM element:
$( ".draggable" ).draggable({
helper: 'clone',
appendTo: '#outer'
});
Then you can have a droppable somewhere:
$('#dropspace').droppable({
accept: '.draggable',
drop: function( event, ui ) {
window.alert('Element dropped at left: ' + ui.position.left + '; top: ' + ui.position.top);
}
});
Proof of concept: http://jsfiddle.net/YvJhE/662/
You still need to move the actual dom element to where it was dropped, or recreate it depending on what you're going to use it for.
The option helper: 'clone'
makes a clone of the item you're dragging automatically so that it can be dragged out of the container:
jQuery(".draggable").draggable({
helper: 'clone',
revert: 'invalid',
appendTo: 'body'
});
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