Google FastButton clicks twice on iOS

前端 未结 2 1056
再見小時候
再見小時候 2021-01-17 02:48

When using MrMaksimize and Alex Blacks implementation of Google FastButton I get two clicks in iOS.

Try this fiddle: http://jsfiddle.net/Cotten/zQsVZ/



        
相关标签:
2条回答
  • 2021-01-17 03:06

    I'm having a similar issue here.

    I was able to fix it by using this solution:

    var clickObject = {
        flag: false,
        isAlreadyClicked: function () {
            var wasClicked = clickObject.flag;
            clickObject.flag = true;
            setTimeout(function () { clickObject.flag = false; }, 100);
            return wasClicked;
        }
    };
    var a = new FastButton(document.getElementById('a'), function() {
        if (!clickObject.isAlreadyClicked()) {
            alert('click');
        } else {
            return;
        }
    });
    

    I'm not sure if it will work with your fast button implementation, but it's worth a shot. My implementation look more like this:

    $('#container').on('click touchstart', 'a.element', function(event) {
        if (!clickObject.isAlreadyClicked()) {
            alert('click');
        } else {
            return;
        }
    });
    

    Best of luck!

    0 讨论(0)
  • 2021-01-17 03:27

    I think the FastButton implementation already prevents the Ghostclick (timeout of a few milliseconds).

    I had the same problem, as I think the problem might be in the fact that you're using and alert (as I was). For some reason (I haven't dived deep into the code), you get another event fired because of the alert. If you're only trying the code out, use "console.log" which is non-blocking instead of alert, and you might see that this second event does not get called.

    Hopefully the idea is not to use the alert command, but if it is, use it with a timeout, which works around the implementation of ghostclick, which is what i think is breaking the behaviour anyway:

    new FastButton(document.getElementById('a'), function() { 
           setTimeout('alert("hello");',500);
    });
    

    Hope it helps.

    Cheers, Miguel

    0 讨论(0)
提交回复
热议问题