I had a similar problem - I needed to position the βboxesβ inside the container, allowing them to overflow from the bottom or right, but not to the left or top. I also had to support changing the position of the container.
Unfortunately, I could not find an elegant solution. As you rightly noted, setting containment through an array of coordinates will determine the metrics associated with documents, so we must work with the position of the container relative to the document.
My little hack was to use the βdocumentβ in the container position for the upper and left limits (I used jQuery offset [1] and a large enough value for the right and lower limits. I used dragstart event [2] to read it again and reset the position in the container viewing window (which updated the containment window to the current container coordinates using the options method [3]).
var $containerEl = $('#container'), $draggableEl = $('#my-draggable'); $draggableEl.on('dragstart', function (e) { $(e.target).draggable('option', 'containment', [ $containerEl.offset().left, $containerEl.offset().top, 15000, 15000 ]); }); $draggableEl.draggable({ containment: [ $containerEl.offset().left, $containerEl.offset().top, 15000, 15000 ] });
[1] http://api.jquery.com/offset/
[2] http://api.jqueryui.com/draggable/#event-start
[3] http://api.jqueryui.com/draggable/#method-option
paulojreis
source share