【问题标题】:Mousedown Event with ipad/iphone Compatibility? - jQuery Mobile与 ipad/iphone 兼容性的 Mousedown 事件? - jQuery 移动
【发布时间】:2010-12-15 10:24:59
【问题描述】:

我用 jquery 写了一个小滚动条。滚动条似乎可以在 PC 和 Mac 上完美运行。但它不适用于触控设备。

我猜这是由于调用了mousedown 属性。如何在 PC 和触摸屏设备上进行这项工作?

谢谢

$('.scroll-nav-up, .scroll-nav-down').live('click', function(){
    $('.scroller-wrap').stop();
    return false;
});


$('.scroll-nav-up').live('mousedown', function(){

    $(this).closest('.item').find('.scroller-wrap').animate({
        top: -($(this).closest('.item').find('.scroller-wrap').height() - 250)
    }, 800);

});


$('.scroll-nav-down').live('mousedown', function(){

    $(this).closest('.item').find('.scroller-wrap').animate({
        top: 0
    }, 800);

});

【问题讨论】:

  • 要获得代码修复的答案 - 发布一个演示并在问题中链接到它,以便人们可以测试什么工作以及如何工作。

标签: jquery jquery-mobile


【解决方案1】:

如果您使用的是 jquery mobile,请尝试处理其新事件 taptaphold

http://jquerymobile.com/demos/1.0a2/#docs/api/events.html

我无法对其进行测试,所以这只是一个想法(我不确定我是否了解您的应用的功能),但您可以尝试将 click 更改为 mouseup 事件。

【讨论】:

    【解决方案2】:

    没有发现什么特别的东西,所以此时我使用了 2 个脚本。第一个脚本标识了 Alastair Campbell 在Detecting touch-based browsing 上编写的触摸屏设备。

    function isTouchDevice() {
       var el = document.createElement('div');
       el.setAttribute('ongesturestart', 'return;');
       if(typeof el.ongesturestart == "function"){
          return true;
       }else {
          return false
       }
    }
    

    然后对常规浏览器使用mousedown 事件,对触摸屏设备使用tap 事件。

    P.S - 同时使用 jQuery 和 jQuery Mobile

    【讨论】:

      猜你喜欢
      • 2011-10-19
      • 2013-06-12
      • 2012-03-31
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多