Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your thinking was correct, you have to make the small boxes greedy droppables and handle the <code>drop</code> event on them. The tricky part is to cancel the drag operation.</p> <p>By default, your draggables should start as <code>revert:'invalid'</code>. You don't have to do anything if they are dragged inside the big box, which in my example uses <code>tolerance:'fit'</code>, so the small boxes must be completely inside to be accepted.</p> <p>I have made the small boxes greedy droppables with <code>tolerance:'touch'</code>, so if the dragged small box touches another small box, it will call the <code>drag</code> handler on it.</p> <p>To cancel the drag operation from a drag handler, you can do a workaround of setting the dragged item to <code>revert:true</code>, which forces it to revert even though it was dropped on an accepting droppable. To make sure you can drag that small box again, on its drag stop event you have to reset <code>revert:'invalid'</code>. The <code>stop</code> event will fire on every successful drop and if it's reverting, it will fire <em>after</em> reverting has completed.</p> <p>You can try out a live demo here: <a href="http://jsfiddle.net/htWV3/1/">http://jsfiddle.net/htWV3/1/</a></p> <p>HTML:</p> <pre><code>&lt;div class="drop"&gt; &lt;div class="drag"&gt;&lt;/div&gt; &lt;div class="drag"&gt;&lt;/div&gt; &lt;div class="drag"&gt;&lt;/div&gt; &lt;div class="drag"&gt;&lt;/div&gt; &lt;div class="drag"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code>.drop { display:inline-block; width:300px; height:200px; border:1px solid silver; background-color:whitesmoke; padding:10px; } .drag { display:inline-block; width:30px; height:30px; border:1px solid silver; background-color:white; } </code></pre> <p>Javascript:</p> <pre><code>$('.drop').droppable({ tolerance: 'fit' }); $('.drag').draggable({ revert: 'invalid', stop: function(){ $(this).draggable('option','revert','invalid'); } }); $('.drag').droppable({ greedy: true, tolerance: 'touch', drop: function(event,ui){ ui.draggable.draggable('option','revert',true); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload