Skip to content

Commit be1ed3b

Browse files
author
李名顺
committed
fix:Fix sortableContainer distance inaccurate
1 parent caf3c4f commit be1ed3b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/SortableContainer/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getElementMargin,
1616
getLockPixelOffsets,
1717
getPosition,
18+
getLinearDistance,
1819
isTouchEvent,
1920
limit,
2021
NodeType,
@@ -191,7 +192,7 @@ export default function sortableContainer(
191192
x: this.position.x - position.x,
192193
y: this.position.y - position.y,
193194
};
194-
const combinedDelta = Math.abs(delta.x) + Math.abs(delta.y);
195+
const combinedDelta = getLinearDistance(Math.abs(delta.x), Math.abs(delta.y));
195196

196197
this.delta = delta;
197198

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export function getContainerGridGap(element) {
272272
return {x: 0, y: 0};
273273
}
274274

275+
export function getLinearDistance(deltaX, deltaY) {
276+
return Math.sqrt(deltaX ** 2, deltaY ** 2);
277+
}
278+
275279
export const KEYCODE = {
276280
TAB: 9,
277281
ESC: 27,

0 commit comments

Comments
 (0)