I have a scenario where I am listening to both CLICK
and MouseDown
events for an object.
On MouseDown I do a startDrag()
. And on Click, I perform something else.
But the problem is that, MouseDown event fires first and it initiates a drag. The click event 开发者_如何学Godoes not fire. How do I solve this issue?
You can listen MouseDown event and when it fires subscribe MouseMove and MouseUp events and remember coordinates of cursor on MouseDown. Then determine a delta (say 1px) which will be a sign of starting dragging. So if MouseMove invokes you check current mouse position and determine if user is really dragging (using your delta). In this case invoke startDrag()
. In other case Click event will be invoked.
And remember unsubscribing events! :)
精彩评论