Search code examples
javascripthtmldrag-and-drop

HTML Drag and Drop - determine position within object


I am trying to determine the position within a div where the drop occurs (relative to the center point). The goal would be to determine if the drop is above, below, right or left. So far, I can only find the coordinates of the event (SyntheticBaseEvent) clientX/Y, but not the coordinates of the target being dropped on. Is there a way to determine this?


Solution

  • You can by getting the coordinates of the div and working from there

    element.getBoundingClientRect();
    

    Hope it helped