Maybe some of the non-default values of droppable's tolerance
option can be a good alternative for you, although they will not do exactly what you are asking for.
From the docs:
Specifies which mode to use for testing whether a draggable is hovering over a droppable. Possible values:
"fit"
: Draggable overlaps the droppable entirely.
"intersect"
: Draggable overlaps the droppable at least 50% in both directions.
"pointer"
: Mouse pointer overlaps the droppable.
"touch"
: Draggable overlaps the droppable any amount.
The default one is "intersect"
. I would consider using either "pointer"
or "touch"
.
Alternatively, if you really need to use the top left corner as a reference, then you should overwrite $.ui.intersect
, which is the function that takes care of checking whether a dragabble and a droppable intersect, based on the tolerance mode. It should return true
if they do or false
otherwise. It looks something like this:
$.ui.intersect = function (draggable, droppable, toleranceMode) {
swtich(toleranceMode) {
// Check if they intersect based on the selected mode.
default:
return false;
}
}
You need to redefine that function and add a custom case
block, while keeping the original modes as well. Otherwise, some other parts of the code that depend on that (maybe some other jQuery UI components), will break.
However, that will only work for jQuery UI < 1.12
. If you are using a newer version, you will have to overwrite some other methods. You can find a detailed answer with code examples of that here: Build the matching option for jQuery UI Droppable's Intersect tolerance