JqueryUI resizes div without dropping the correct location

I have a “drawer” that you can drag and drop onto a divpable column. The drag-and-drop box is snapped to the dropdown div using the JqueryUI position function, but when I resize the draggable rectangle 3x in height or more, I can no longer move the box with one “droppable div” below.

$( ".ru" ).droppable({
  activeClass: "active",
  hoverClass: "hover",
  drop: function(event, ui) {
    ui.draggable.position({
      of: $(this),
      my: 'top left',
      at: 'top left'
    });
  }
});

Hopefully this makes sense, basically, to recreate the problem, resize the draggable box 3 times in height and try to drag it 1 div down.

jsfiddle: link

Thanks for any help.

+4
1

my at . - "center", , . " " " ".

: .droppable(), droppable, #box .

$.ui.intersect = function(draggable, droppable, toleranceMode) {

  var draggableLeft, draggableTop,
    x1 = (draggable.positionAbs || draggable.position.absolute).left,
    y1 = (draggable.positionAbs || draggable.position.absolute).top + 15,
    x2 = x1 + draggable.helperProportions.width,
    y2 = y1 + draggable.helperProportions.height,
    l = droppable.offset.left,
    t = droppable.offset.top,
    r = l + droppable.proportions.width,
    b = t + droppable.proportions.height;

  return (l < x1 + (draggable.helperProportions.width) && 
    x2 - (draggable.helperProportions.width) < r && 
    t < y1 + 1 && 
    b > y1 - 1); 
};

$( "#box" ).draggable({
  revert: "invalid",
});

$( ".ru" ).droppable({
  hoverClass: "hover",
  tolerance: "custom", //added this line
  drop: function(event, ui) {
    ui.draggable.position({
      of: $(this),
      my: 'left top', //edited this line
      at: 'left top' //edited this line
    });
  }
});

: https://jsfiddle.net/joL53wkq/5/

+2

Source: https://habr.com/ru/post/1621953/


All Articles