Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `greedy: true`
- $(this).droppable( 'disable' );
- for ( var i=0; i<=19; i++ ) {
- var images = 'images/slot' + slotNumbers[i] + '.jpg';
- $('<div class="placeholder"><div class="img-slot"></div></div>').attr('id', 'slot'+slotNumbers[i]).data( 'slotNumbers', slotNumbers[i] ).appendTo( '#imgSlots' ).droppable( {
- accept: '#images img',
- hoverClass: 'hovered',
- drop: handleDropEvent,
- activate: handleDragEvent
- });
- 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);
- }
- }
- 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);
- }
- }
- $(this).droppable( 'disable' );
- $(this).droppable( 'enable' );
- drop: function(event,ui){
- ui.draggable.addClass( 'dropped' ); // taken from your code & I used to change color
- ui.draggable.data('droppedin',$(this)); // associate the container
- $(this).droppable('disable'); // disable the droppable
- }
- drag: function(event,ui){
- if($(this).data('droppedin')){
- $(this).data('droppedin').droppable('enable'); v// re-enable
- $(this).data('droppedin',null); // de-associate
- $(this).removeClass( 'dropped' ) // remove class
- }
- }
Add Comment
Please, Sign In to add comment