Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed draggable position bouncing when draggable is scaled and position is set #150

Merged
merged 2 commits into from
Apr 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed draggable position bouncing when draggable is scaled and positi…
…on is set

-The bouncing happened because there was incorrect position calculation, the position was increased from scale that it was out of bounds and boundsCheck put it back in incorrect position.
  • Loading branch information
agnitos committed Mar 20, 2019
commit 6bca65b9a817284965806c499be1c6c33d989f4e
20 changes: 10 additions & 10 deletions projects/angular2-draggable/src/lib/angular-draggable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
}

private transform() {
// done to prevent the element from bouncing off when
// the parent element is scaled and element is dragged for first time
if (this.tempTrans.x !== 0 || this.tempTrans.y !== 0) {
if (this.isDragged === false) {
this.oldTrans.x = this.currTrans.x * this.scale;
this.oldTrans.y = this.currTrans.y * this.scale;
}
this.isDragged = true;
}

let translateX = this.tempTrans.x + this.oldTrans.x;
let translateY = this.tempTrans.y + this.oldTrans.y;

Expand All @@ -209,16 +219,6 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
translateY = Math.round(translateY / this.gridSize) * this.gridSize;
}

// done to prevent the element from bouncing off when
// the parent element is scaled and element is dragged for first time
if (this.tempTrans.x !== 0 || this.tempTrans.y !== 0) {
if (this.isDragged === false) {
this.oldTrans.x = this.currTrans.x * this.scale;
this.oldTrans.y = this.currTrans.y * this.scale;
}
this.isDragged = true;
}

if (this.scale && this.scale !== 0 && this.isDragged) {
translateX = translateX / this.scale;
translateY = translateY / this.scale;
Expand Down