cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.81k forks source link

_initEvents() - bindToWrapper bad behavior and wrong documentation #614

Open rodneyrehm opened 10 years ago

rodneyrehm commented 10 years ago

I just lost a couple of hours figuring out why scrolling a non-IScroll panel would trigger a click where it shouldn't have. It turns out IScroll binds listeners to window unless told to contain itself to a specific region using bindToWrapper: true.

The docs specifically talk about the move event being bound to the document. In reality much many more events (mousemove, mousecancel, mouseup, MSPointerMove, MSPointerCancel, MSPointerUp, touchmove, touchcancel, touchend) are bound to window.

I have multiple IScroll instances in off-viewport elements. The main document scrolls natively. because I use click: true in my IScroll instances, any touchcancel is caught by one of the IScrolls and a click event is fired. Right now the only solution is to either not use click: true, or make sure all IScrolls have bindToWrapper: true. The former is impossible, the latter annoying because scrolling stops once you leave the wrapper element.

a) the docs should reflect the reality of IScroll's event binding b) I think the *move, *cancel, *up event handlers should be bound on mousedown, MSPointerDown, touchstart respectively (and cleaned up after move/cancel/up) to make sure that IScroll cannot mess with the page's content outside its domain. c) If persistent global events (like touchcancel on window) are used, think about binding one listener and have it delegate to the proper IScroll instance instead of binding a listener for each instance. That would also prevent accidental handling of events

cubiq commented 10 years ago

thanks for the heads-up. I'll fix the docs and try to find a solution for the others.

b) actually is how it was at the beginning but I had to remove event loading/unloading because Android really doesn't like it. It was the 2.x time so I don't know if we should still care and honestly I haven't done tests recently. But anyway, that is by design.

rodneyrehm commented 10 years ago

I'd much prefer a solution that did the right thing by default and changed behavior when necessary. It doesn't make your code any simpler, but it segments "bad behavior". I don't like polluting modern browsers who get things right with crap we have to throw at old browsers that barely deserve the name.

cheers :)