Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable drop if div has already been dropped?
    primarykey
    data
    text
    <p>I've created a drag and drop game in order to start teaching myself jquery. Everything seems to be working but you can drop more than one item onto the same square. I want to disable droppable if the place holder has an image in it.</p> <p>I've looked into:</p> <pre><code>`greedy: true` </code></pre> <p>That disables the drop but I'm not sure how to enable it again and also:</p> <pre><code>$(this).droppable( 'disable' ); </code></pre> <p>I can get these both to disable the drop but not sure how I get them to enable it again if the block/image reverts back to its original position or is moved to another square.</p> <p>Full version: <a href="http://creativelabel.co.uk/drag-and-drop/" rel="nofollow">http://creativelabel.co.uk/drag-and-drop/</a></p> <p>UPDATE: This is the code for the droppable slots.</p> <pre><code> for ( var i=0; i&lt;=19; i++ ) { var images = 'images/slot' + slotNumbers[i] + '.jpg'; $('&lt;div class="placeholder"&gt;&lt;div class="img-slot"&gt;&lt;/div&gt;&lt;/div&gt;').attr('id', 'slot'+slotNumbers[i]).data( 'slotNumbers', slotNumbers[i] ).appendTo( '#imgSlots' ).droppable( { accept: '#images img', hoverClass: 'hovered', drop: handleDropEvent, activate: handleDragEvent }); </code></pre> <p>This is <code>drop:</code> event code:</p> <pre><code> function handleDropEvent( event, ui ) { var slotNumber = $(this).data( 'slotNumbers' ); var imgNumber = ui.draggable.data( 'number' ); ui.draggable.addClass( 'dropped' ); $(this).droppable( 'disable' ); ui.draggable.position( { of: $(this), my: 'right top', at: 'right top' } ); if ( slotNumber == imgNumber ) { ui.draggable.addClass( 'img-match' ); ui.draggable.data("valid", true); imgMatch++; } else { if(ui.draggable.data("valid")) { imgMatch--; ui.draggable.data("valid", false); } } </code></pre> <p>The <code>activate:</code> code:</p> <pre><code> function handleDragEvent( event, ui ) { $(this).droppable( 'enable' ); if(ui.draggable.data("valid")) { imgMatch--; $('input[name=Score]').val(imgMatch); $('#score h1').text(imgMatch); ui.draggable.data("valid", false); } } </code></pre>
    singulars
    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.
 

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