daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `greedy: true`
  2.    
  3. $(this).droppable( 'disable' );
  4.    
  5. for ( var i=0; i<=19; i++ ) {
  6.   var images = 'images/slot' + slotNumbers[i] + '.jpg';
  7. $('<div class="placeholder"><div class="img-slot"></div></div>').attr('id', 'slot'+slotNumbers[i]).data( 'slotNumbers', slotNumbers[i] ).appendTo( '#imgSlots' ).droppable( {
  8.       accept: '#images img',
  9.       hoverClass: 'hovered',
  10.       drop: handleDropEvent,
  11.       activate: handleDragEvent
  12. });
  13.    
  14. function handleDropEvent( event, ui ) {
  15.   var slotNumber = $(this).data( 'slotNumbers' );
  16.   var imgNumber = ui.draggable.data( 'number' );
  17.   ui.draggable.addClass( 'dropped' );
  18.   $(this).droppable( 'disable' );
  19.   ui.draggable.position( { of: $(this), my: 'right top', at: 'right top' } );
  20.  
  21.   if ( slotNumber == imgNumber ) {
  22.     ui.draggable.addClass( 'img-match' );
  23.     ui.draggable.data("valid", true);
  24.  
  25.     imgMatch++;
  26.   }  else {
  27.       if(ui.draggable.data("valid")) {
  28.          imgMatch--;
  29.          ui.draggable.data("valid", false);
  30.       }
  31.   }
  32.    
  33. function handleDragEvent( event, ui ) {
  34.    $(this).droppable( 'enable' );
  35.    if(ui.draggable.data("valid")) {
  36.          imgMatch--;
  37.          $('input[name=Score]').val(imgMatch);
  38.          $('#score h1').text(imgMatch);
  39.          ui.draggable.data("valid", false);
  40.    }
  41.  }
  42.    
  43. $(this).droppable( 'disable' );
  44.    
  45. $(this).droppable( 'enable' );
  46.    
  47. drop: function(event,ui){
  48.     ui.draggable.addClass( 'dropped' ); // taken from your code & I used to change color
  49.  
  50.    ui.draggable.data('droppedin',$(this)); // associate the container
  51.     $(this).droppable('disable'); // disable the droppable
  52. }
  53.    
  54. drag: function(event,ui){
  55.        if($(this).data('droppedin')){
  56.            $(this).data('droppedin').droppable('enable'); v// re-enable
  57.            $(this).data('droppedin',null);  // de-associate
  58.            $(this).removeClass( 'dropped' ) // remove class
  59.        }
  60.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top