jairajs89 / Touchy.js

A simple light-weight JavaScript library for dealing with touch events
1.08k stars 65 forks source link

consider mouseup when mouse leave an element #9

Closed arenevier closed 11 years ago

arenevier commented 11 years ago

Hi, when using the mouse: mousedown starts triggering the move. But if we leave the document without releasing the button, and release the button from outside the page, the page does not catch the release event, and when we come back to the element (with button released), the move are still triggered. This is quite confusing. So, as a workaround, maybe you can cancel the move when mouse leaves an element.

Here is a quick patch I use to get a better behaviour

diff --git a/touchy.js b/touchy.js index eee2f1e..75a4a62 100644 --- a/touchy.js +++ b/touchy.js @@ -386,6 +386,7 @@

    if ( this.handleMouse ) {
        bind(this.elem, 'mousedown' , this.mousedown() );
jairajs89 commented 11 years ago

Good idea! I should have done that the first time.

I've now implemented it in commit 35da599. I also added additional logic to insure that the mouseout is leaving to another element (not one of its children).