Don't flip direction to zero when mouse/touch is stationary.
Mousemove/touchmove events keep on firing (once per second or so) even if the pointer position is not changing. This resulted in the direction being reset to zero if one holds the mouse/finger stationary for a while. Since __checkPosition only has a two-way branch, a zero direction always fell into the second branch, resulting in sporadic broken behaviour for backwards (right, positive direction) swipes while forward (left, negative direction) swipes worked perfectly.
Specifically:
- Swipe backwards (right) past the snap threshold and release immediately, page changes and everything is fine.
- Swipe backwards (right), hold the mouse steady for a few seconds, then release. Page snaps back to its previous position (in fact, it is being advanced in the wrong direction!), page index is incremented in the wrong direction, and is now out of sync with the displayed page. Future swipes keep the page index off by one.
This is the minimal fix, it would probably make sense to also add a branch in __checkPosition to do the right thing when directionX == 0, since that could still happen when snapThreshold == 0.
Sorry, this isn't a complete fix. I'll send a proper fix in a bit.
would you integrate this into the latest version so your name appears between the collaborators? Thanks and sorry for not merging this earlier... I really haven't seen this pull request before, sorry again!
Doesn't look like f1e1904 ever got merged.
@cubic Here's the patch by @simonratner applied to the latest repo: #39