cubiq / iscroll

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

click event fired twice times on iScroll v5 #547

Closed kimleng closed 10 years ago

kimleng commented 10 years ago

hello, I have a problem with click event on iScroll 5. Some elements, they fired only one time. But some elements, they fired twice times. Even I changed to tap, it is also same issue. How should I do?

laurentperez commented 10 years ago

We hit a similar problem. Either you built two instances and forgot to use destroy() to remove the double event handlers, or, are you seing this on Android 4.0.x ?

kimleng commented 10 years ago

I will detail my code as following:

page = {
        iScroll : undefined,
        init : function(){
               var options = {
                      mouseWheel: true,
                      probeType: 3
               }
               // Here I check device that I want to add click event.
               // On ios device, if we don't add click event, it won't handler. But android will.
               // But if we add click event to both ios and android, android will fired twice times.
               if(os == ios){ // This line, I am just example only
                      options.click = true;
               }

               if(page.iScroll==undefined){
                     page.iScroll = new IScroll("#target",options);
                     page.iScroll.on('scroll', page.updateContent);
                     page.iScroll.on('scrollEnd', page.updateContent);
                     document.addEventListener('touchmove',function(e){e.preventDefault();},false);
               }
        },
        updateContent : function(){
              //do something
        }
}

Even I have checked device os to add click event. But on iphone, some element fired once, and some element fired twice. And one more thing on iphone 4, when we were scrolling the content with images, it seem not smoothly. Also on LG Devices, iScroll v5 doesn't work smoothly on it. It is too slow while I am scrolling content either with images or without images.

kimleng commented 10 years ago

I just found that some elements that fired twice times if I apply click event "({ click:true })" to iphone. Those elements are button object.

laurentperez commented 10 years ago

yes, you need click: true for ios and android to fire the click, and yes stock android will fire it 2 times : see https://github.com/cubiq/iscroll/pull/548 where I did the fix for android

I did not see double clicks on ios. Perhaps it is because you registered double click handlers ?

For us v5.0.6 is smooth but I did not test with images. Did you use :hover on images ?

gimox commented 10 years ago

same problem. Ios fire twice the buttons. For example, Bootstrsap modal create a button and it fire twice in ios with click=true. The modal appear and disappear immediatly. So a solution for now is use only <a> but is not a good solution. i'm waiting a 5.0.7 with correction fix!!!

cubiq commented 10 years ago

can you confirm this on the latest version?

gimox commented 10 years ago

seem to be fixed now. (5.09 version )

kafka-yu commented 10 years ago

version 5.2.1 still has this issue!

jhnns commented 10 years ago

Duplicate #742?

carlhopf commented 10 years ago

Yup, should be a duplicate and i can confirm that 5.1.2 still has this issue (chrome desktop).

valnub commented 9 years ago

Seeing the same problem in 5.1.1. Is this fixed in the newest 5.1.3? @cubiq Please re-open ticket. Seems like the problem still exists and has not been fixed in 5.0.9

salcott commented 8 years ago

Still has the problem with v5.1.3 ....

sculove commented 8 years ago

@salcott how about using iScroll v5.2.0 ?

wv1124 commented 8 years ago

iScroll v5.2.0 ~ (c) 2008-2016 Matteo Spinelli ~ http://cubiq.org/license mac chrome 52.0.2743.82 (64-bit)

iscroll-probe.js:264 Uncaught TypeError: Cannot assign to read only property 'view' of object '#'me.click @ iscroll-probe.js:264_end @ iscroll-probe.js:629handleEvent @ iscroll-probe.js:1650