Skip to content

Commit

Permalink
Fix image drag preview coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 30, 2015
1 parent 7e653f9 commit 0be5806
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/OffsetHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ export function getEventClientOffset(e) {
}

export function getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint) {
const dragPreviewOffsetFromClient = getElementClientOffset(dragPreview);
const isImage = dragPreview instanceof Image;
const dragPreviewNode = isImage ? sourceNode : dragPreview;

const dragPreviewNodeOffsetFromClient = getElementClientOffset(dragPreviewNode);
const offsetFromDragPreview = {
x: clientOffset.x - dragPreviewOffsetFromClient.x,
y: clientOffset.y - dragPreviewOffsetFromClient.y
x: clientOffset.x - dragPreviewNodeOffsetFromClient.x,
y: clientOffset.y - dragPreviewNodeOffsetFromClient.y
};

const { offsetWidth: sourceWidth, offsetHeight: sourceHeight } = sourceNode;
const { anchorX, anchorY } = anchorPoint;
const isImage = dragPreview instanceof Image;

let dragPreviewWidth = isImage ? dragPreview.width : sourceWidth;
let dragPreviewHeight = isImage ? dragPreview.height : sourceHeight;
Expand Down

0 comments on commit 0be5806

Please sign in to comment.