KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

Setting Drag Tolerance

Open stewartl60 opened this issue 13 years ago • 4 comments

We are encountering an issue where Kinetic is confusing the click and drag event. Boils down to the user clicking and moving their mouse ever so slightly, drag is killing the click event.

Has anyone toyed around with setting a drag tolerance? Anyone on here experienced the same issues?

Working off of v4.0.5.

stewartl60 avatar Jan 21 '13 21:01 stewartl60

This is probably related to the issue people are having related to the mouseup event not being detectable during drag and drop after some rendering optimizations that I made. I'll address this issue by the next release:

https://github.com/ericdrowell/KineticJS/wiki/Release-Schedule/_edit

ericdrowell avatar Jan 21 '13 21:01 ericdrowell

The trouble I have is that dd.moving evaluates to true on the node's _mouseup event. The _endDrag is the last function to execute.

Temporary work around, store the coordinates on _mousedown. Then on _mouseup you can define a tolerance check if dd.moving is true. Selected 5 pixels for now. Code below if anyone is interested, note you need to fire _endDrag before handling the click event.

var click_position = this.getUserPosition(); var diff_x = Math.abs(this.click_position.x - click_position.x); var diff_y = Math.abs(this.click_position.y - click_position.y); this.click_position = false;

//give user a 5 pixel click tolerance to fire if(diff_y <= 5 || diff_x <= 5) { this.clickStart = false;

// end drag and drop if(dd) { dd._endDrag(evt); }

shape._handleEvent('click', evt); }

stewartl60 avatar Jan 21 '13 23:01 stewartl60

haven't forgotten about this issue - it'l just take a little time to get to it.

ericdrowell avatar Aug 28 '13 05:08 ericdrowell

Close via https://github.com/ericdrowell/KineticJS/commit/0b93e21e0b9e11165dfed7574dbafa0ae2a144e0.

Kinetic.dragDistance = 5;
// or
node.dragDistance(5);

lavrton avatar Apr 30 '14 15:04 lavrton