Skip to content

Commit

Permalink
fix(to-drag): ignore adsorb compute when without moving
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-kfd committed Aug 22, 2024
1 parent 843444f commit b4c6985
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/to-drag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ToDrag {
height = 0
maxX = 0
maxY = 0
needComputeAdsorb = true // 是否需要计算吸附, 只有产生了Move才需要计算
private options: ToDragOptions
private scrollbarWidth: number
private startX = 0
Expand Down Expand Up @@ -158,6 +159,7 @@ export class ToDrag {
}

setStartInfo (x: number, y: number, e?: TouchEvent | MouseEvent) {
this.needComputeAdsorb = false
this.setPosition();
this.setLimit();
this.startX = x - this.left;
Expand All @@ -176,6 +178,7 @@ export class ToDrag {
return;
}
e.preventDefault();
this.needComputeAdsorb = true
let dragX, dragY;
const x = this.isTouch ? (e as TouchEvent).changedTouches[0].clientX : (e as MouseEvent).x;
const y = this.isTouch ? (e as TouchEvent).changedTouches[0].clientY : (e as MouseEvent).y;
Expand Down Expand Up @@ -211,6 +214,7 @@ export class ToDrag {

handleAdsorb () {
// if (this.options.isAbsolute) return;
if (!this.needComputeAdsorb) return
const endPoint = [this.left + this.width / 2, this.top + this.height / 2];
let maxX = 0
let maxY = 0
Expand Down Expand Up @@ -337,14 +341,14 @@ const mounted = (el: HTMLElement, binding: DirectiveBinding, userOptions?: ToDra
...customGlobalOptions,
...value
};
(el as any).$toDarg = new ToDrag({
(el as any).$toDrag = new ToDrag({
el,
options
});
};

const unmounted: DirectiveHook = (el: any) => {
el.$toDarg && el.$toDarg.destroy();
el.$toDrag && el.$toDrag.destroy();
};

export const ToDragDirective: ObjectDirective = {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/to-drag/example/example6.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default defineComponent({
return {
options: {
isAbsolute: true,
// adsorb: 2,
// adsorbOffset: 10,
needComputeBorder: true // default is true, will compute parent border width
}
};
Expand Down

0 comments on commit b4c6985

Please sign in to comment.