iPad/iPhone兼容的Mousedown事件?- jQuery Mobile

4
我用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);

});

为了获得代码修复的答案 - 发布一个演示并在问题中链接它,以便人们可以测试哪些方法有效。 - naugtur
2个回答

1

没有发现特别的问题,所以我目前使用了两个脚本。第一个脚本是根据Alastair Campbell在检测基于触摸的浏览中编写的内容来识别触摸屏设备。

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。


1
如果您正在使用jQuery Mobile,请尝试处理其新事件taptaphold

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

我无法测试它,所以这只是一个想法(我不确定我是否理解您的应用程序在做什么),但您可以尝试将点击更改为鼠标松开事件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接