multiple droppable

前端 未结 1 1010
有刺的猬
有刺的猬 2021-01-14 16:12

I\'ve have multiple droppable divs (which all have the same size) and one draggable div. The draggable div is 3 times bigger than one droppable. When I drag the draggable di

1条回答
  •  有刺的猬
    2021-01-14 16:49

    Maybe like this? Put up a demo here.

    $(".droppable").droppable({
        drop: function (event, ui) {
            var $draggable = $(ui.draggable);
    
            var draggableTop    = $draggable.offset().top;
            var draggableHeight = $draggable.height();
            var draggableBottom = draggableTop + draggableHeight;
    
            $droppables = $(".droppable");
    
            $droppablesCoveredByDraggable = $droppables.filter( function() {
                var $droppable  = $(this);
                var top                 = $droppable.offset().top;
                var height          = $droppable.height();
                var bottom          = top + height;
    
                var isCoveredByDraggable = top <= draggableBottom && bottom >= draggableTop;
                return isCoveredByDraggable;
            });
    
            //example: mark the droppables that are covered
            $droppables.removeClass("marked");
            $droppablesCoveredByDraggable.addClass("marked");
        }
    });
    

    0 讨论(0)
提交回复
热议问题