davidaurelio / TouchScroll

TouchScroll is a JavaScript- and CSS 3-based scroller for devices using Webkit Mobile. It is meant to mimic “native” scrolling feeling and behavior as much as possible.
http://uxebu.com/blog/2010/04/27/touchscroll-a-scrolling-layer-for-webkit-mobile/
BSD 2-Clause "Simplified" License
474 stars 61 forks source link

Preventing next click after scrolling #12

Open iscy opened 13 years ago

iscy commented 13 years ago

On the iPhone:

  1. Scroll on a page
  2. Hit an element that has onClick() function => Nothing happens
  3. Hit it again => Works

The function: _preventNextClick() is the root cause of this issue. I'm not sure why this function was introduced in the first place... but removing its call from onTouchMove fixes my issue. I think the handler should be removed from onTouchEnd().

iscy commented 13 years ago

Here is a patch that fixes the issue by removing the prevent handler on onTouchEnd().

Index: web/touchscroll.js
===================================================================
--- web/touchscroll.js  (revision 5168)
+++ web/touchscroll.js  (working copy)
@@ -639,6 +639,8 @@

                                this.startFlick(flickVector, flickDuration);
                        }
+
+                       scroller.removeEventListener("click", preventHandler, true);
                }

                if(!(this.isAnimating())){
@@ -667,13 +669,15 @@
        _preventNextClick: function _preventNextClick(){
                var scroller = this.scrollers.container;
                scroller.style.webkitTapHighlightColor = "transparent";
-               scroller.addEventListener("click", function prevent(event){
-                       event.stopPropagation();
-                       this.removeEventListener("click", prevent, true);
-                       this.style.webkitTapHighlightColor = "";
-               }, true);
+               scroller.addEventListener("click", preventHandler, true);
        },

+       _preventHandler: function _preventHandler(event) {
+               event.stopPropagation();
+               scroller.removeEventListener("click", preventHandler, true);
+               scroller.style.webkitTapHighlightColor = "";
+       },
+
        isAnimating: function isAnimating(){
                var timeouts = this._animationTimeouts;
                var hasTimeouts = timeouts.e.length > 0 || timeouts.f.length > 0;
davidaurelio commented 13 years ago

Thanks for the patch … this will be fixed with the rewrite, I just don’t have much time left to finish it at the moment.

ruiquelhas commented 11 years ago

This is still happening (at least on Android phones), and I don't see that _preventNextClick function anywhere in the code, so I don't know how can I patch it. Any workaround for this? The project doesn't seem pretty active right now, but i'm hoping someone can answer me.