【问题标题】:Swipe event triggers tap event for ipod touch滑动事件触发 ipod touch 的点击事件
【发布时间】:2011-07-01 16:13:29
【问题描述】:

我正在使用 jquery mobile beta 和 jquery 1.6。 在 ipod touch 上,滑动事件也会触发点击事件。 这个问题在安卓设备上没有发生。 我正在尝试用谷歌搜索解决方案,但看起来有同样问题的人并不多。我缺少一些非常基本的东西吗??

$("div.totapandswipe").bind('tap',function(event, ui){
    alert('event');
});

$("div.totapandswipe").bind('swipe',function(event, ui){
            alert('event');
});

感谢您的帮助!

【问题讨论】:

  • 能否提醒事件类型:alert('Event: '+event.type);
  • 是的..它会提醒正确的滑动事件滑动并点击点击...现在我看到正确的代码根据触发的事件执行,但是在我尝试了几次之后,我看到对于滑动事件,我最终会收到点击警报。唯一可能干扰的是滚动视图插件(jquerymobile 下的实验),我使用它来包含滑动区域..将更多地研究该插件(并返回)并查看是否存在 jquery 移动滑动冲突和滚动视图滑动...非常感谢您的时间!
  • 在运行了一些测试之后,看起来你是对的:jsfiddle.net/phillpafford/hJtAQ/9 也许你可以使用 preventDefault() 并触发单个事件。这也可能是一个错误
  • 我也想解决这个问题。

标签: jquery jquery-mobile swipe tap


【解决方案1】:

我发现我需要将 unbind('click') 作为我的 bind('swipeleft swiperight') 函数中的第一个选项。由于我的滑动进入了一个新页面,该页面重新绑定了它刚刚离开的页面的“点击”事件。我的实用工具是一张抽认卡,点击它会带来一张新卡片,然后轻扫它就会翻过来。祝你好运。

$('#flashVerse').bind('swipeleft swiperight', function(event) {
    console.log(event.type);
    $('#flashVerse').unbind('click');
    if(event.type == 'swipeleft') {
        $.mobile.changePage('flashReference','flip');
    } else {
        $.mobile.changePage('flashReference','flip',true,false);
        console.log('SWIPERIGHT');
    }
});

$('#flashReference').live('pageshow',function(event,ui){
    if((tipsOn() || ls.getItem('tipFlash') == '1') && ui.prevPage.attr('id')!='flashVerse') {
        ls.setItem('tipFlash','0');
        var msg = 'Swipe to flip the card.\n Tap for a new card.\nuse Options to turn Tips back on.';
        if(phoneGap) navigator.notification.alert(msg,dummy,'Flash Cards','OK');
        else alert(msg);
    }
    $('#lnkFlashVerse').addClass('ui-btn-active').addClass('ui-state-persist');
    $('#lnkFlashReference').removeClass('ui-btn-active').removeClass('ui-state-persist');
    $('#flashReference').bind('click', function(event) {
        console.log(event.type);
        newFlashCard();
        //$('#flashReference div[data-role="content"]').append('clicked ');
    });
});

【讨论】:

    【解决方案2】:

    这似乎对我有所帮助:

    $("selector").swiperight(function (e) {
      if (e.type === "swiperight") {
        myHandler(e);
      }
    });
    

    这将是一个问题,这很糟糕。这个jqm bug了吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      • 2020-09-20
      • 2016-07-01
      相关资源
      最近更新 更多