Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

calculated setDragImage offset #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thenetsmith
Copy link

Addresses issue #238.

@Stalinko
Copy link

It works only in rare cases when dnd-handler is placed right inside dnd-draggable. But it doesn't work correct when between dnd-handler and dnd-draggable are other tags.
Here is more universal code:

if (event._dndHandle && event.dataTransfer.setDragImage) {
    var handleOffset = element.find('[dnd-handle]').offset();
    var elementOffset = element.offset();
    var offX = (handleOffset && elementOffset ? handleOffset.left - elementOffset.left : 0) + event.offsetX;
    var offY = (handleOffset && elementOffset ? handleOffset.top - elementOffset.top : 0) + event.offsetY;
    event.dataTransfer.setDragImage(element[0], offX, offY);
}

@marceljuenemann
Copy link
Owner

@Stalinko you seem to be using jQuery, which is not a required dependency of this directive and can therefore not be used. I'll take a closer look at this when I do another release.

@marceljuenemann marceljuenemann added this to the 2.x milestone Jan 16, 2017
@Stalinko
Copy link

@marceljuenemann, yeah you're right. It was the easiest way for me to calculate absolute offset of an element, however obviously it can be achieved without jQuery (http://youmightnotneedjquery.com/#offset)

jpuffer added a commit to jpuffer/angular-drag-and-drop-lists that referenced this pull request Mar 29, 2017
@jpuffer
Copy link

jpuffer commented Mar 29, 2017

I made a branch with these changes which does not rely on jQuery. Please take a look! Would love to see this included in the next release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants