【问题标题】:Touchend and Sliding Finger Off Button触控端和滑动手指关闭按钮
【发布时间】:2013-04-07 00:28:18
【问题描述】:

我有一个音量按钮,可以绑定到 touchstart 和 mousedown 事件,以及 touchend 和 mouseup 事件(我也尝试过 touchleave 和 touchcancel)。

当用户将手指放在按钮上并抬起手指时,它会按预期调用结束处理程序。但是,如果用户将手指从按钮上滑开然后抬起手指,则该事件永远不会被触发(这会导致音量控制无限递减或递增的问题)。

我尝试将 touchend 事件绑定到 window 对象,但这似乎没有任何作用。这是我目前拥有的:

$('#volume-wrap button').on('touchstart mousedown', function() {
    if (this.id == 'volume-down')
        volume_timer = setInterval(function(){main.hud.adjustVolume('down')}, 100);
    else
        volume_timer = setInterval(function(){main.hud.adjustVolume('up')}, 100);
});

$(window).on('touchend mouseup', function() {
    if (volume_timer) {
        clearInterval(volume_timer);
        volume_timer = 0;
    }
});

【问题讨论】:

    标签: touch multi-touch android-browser


    【解决方案1】:

    尝试将 e.preventDefault() 添加到 touchstart 事件。 安卓浏览器有bug。

    见:http://code.google.com/p/android/issues/detail?id=4549

    更新: 如需更好的解释,请参阅 SystemParadox 答案:https://stackoverflow.com/a/11613327/757086

    【讨论】:

      猜你喜欢
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多