jQuery droppable - receiving events during drag over (not just on initial drag over)

前端 未结 5 1796
忘掉有多难
忘掉有多难 2021-01-31 09:50

I am using jQuery droppable (in conjunction with jQuery draggable) to allow the user to add rows to an HTML table by dragging items from a list and dropping them on the table.

5条回答
  •  借酒劲吻你
    2021-01-31 10:24

    Another method is to add a class or other elector to the hint element. Then in the draggable definition, on the drag handler, update the hint position:

    $('#dropArea').droppable({
            over: function(event, ui) 
                // Create a clone 50 pixels above and 100 to the left of drop area 
                $('#someHint').clone()
                        .css({
                            position: 'absolute',
                            top: ui.offset.top+50,
                            left: ui.offset.left-50
                        })
                        .addClass("clone")          // Mark this as a clone, for hiding on drop or out
                        .addClass("dragHelper")     // Mark this as a hint, for moving with drag
                        .appendTo(document.body)
    
    
            },
            out: function(event, ui) {
                $('.clone').remove();                       // Remove any hints showing
            },
            drop: function(event, ui) {
                $('.clone').remove();                       // Remove any hints showing
            }
        });
    
    $("#mydiv").draggable({
            drag: function(event, ui) {
                $('.dragHelper').css('left',ui.offset.left);
                $('.dragHelper').css('top',ui.offset.top);
            }
    
    });
    

提交回复
热议问题