jquery droppable accept

后端 未结 8 2157
轻奢々
轻奢々 2020-12-13 07:02

Can anyone tell me how I can write a function in accept condition and then how does it finds out that what to accept and what not to accept. For example, I want to accept

8条回答
  •  Happy的楠姐
    2020-12-13 07:24

    I've figured out a solution that works based on the condition that no draggable should be placed in a droppable already occupied by another draggable:

    $(".placement").droppable({
        accept: function(elm) {
            // only allow draggables to the placement if there's no other draggable 
            // in the droppable
            if (!$(this).attr('isbusy'))
                return true;
        },
        drop: function(event, ui) {
            $(this).attr('isbusy', 'yeap'); // fill key with something
    
            var draggable = $(ui.draggable[0]);
            // free the draggable's previous droppable 
            if (draggable.attr('droppable')) {
                $('#' + draggable.attr('droppable')).attr('isbusy', '');
            }
    
            // save the new draggable's droppable
            draggable.attr('droppable', $(this).attr('id'));
        },
    });
    

提交回复
热议问题