【问题标题】:Google FastButton clicks twice on iOSGoogle FastButton 在 iOS 上点击两次
【发布时间】:2013-01-15 10:44:31
【问题描述】:

当使用Google FastButton 中的MrMaksimize and Alex Blacks implementation 时,我在iOS 中获得了两次点击。

试试这个小提琴:http://jsfiddle.net/Cotten/zQsVZ/

var a = new FastButton(document.getElementById('a'), function() {
 alert('click');
});

<div id="a">First click me</div>
<div id="b">Then, click here and nothing should happen... but it does :(</div>
  • 放大结果窗格
  • 点击显示警报的绿色按钮
  • 按下确定,一切正常
  • 然后点击没有FastButton(..)的红色或蓝色div
  • 它再次触发警报:(

我在 iOS 5.1 的 iPhone 4S iOS 6 和 iPad 3 上遇到了这种错误行为。

在安卓上似乎可以工作。

jquery.tappable.js 出现同样奇怪的行为。

谢谢!

【问题讨论】:

    标签: javascript mobile-safari


    【解决方案1】:

    我遇到了类似的问题here

    我能够通过使用this 解决方案来修复它:

    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;
        }
    });
    

    我不确定它是否适用于您的快速按钮实现,但值得一试。我的实现看起来更像这样:

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

    祝你好运!

    【讨论】:

      【解决方案2】:

      我认为 FastButton 实现已经阻止了 Ghostclick(几毫秒的超时)。

      我遇到了同样的问题,因为我认为问题可能在于您正在使用和提醒(就像我一样)。由于某种原因(我没有深入研究代码),由于警报,您会触发另一个事件。如果您只是尝试代码,请使用非阻塞的“console.log”而不是警报,您可能会看到第二个事件没有被调用。

      希望这个想法不是使用警报命令,但如果是,请在超时后使用它,这可以解决 ghostclick 的实现,我认为这无论如何都会破坏行为:

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

      希望对你有帮助。

      干杯, 米格尔

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-23
        • 1970-01-01
        • 2023-03-06
        • 1970-01-01
        相关资源
        最近更新 更多