2012-07-05 64 views
3

我有一些Jquery滚动条。Jquery - 检测手机浏览器的最佳方式? (mousedown/touchmove)

对于桌面浏览器我用这样的结构:

holder.bind('mousedown.rotate', function(e){ 
    //some actions 
    doc.bind('mousemove.dragrotate', function(e){ 
     //some actions   
    }); 
    doc.bind('mouseup.dragrotate', function(){ 
     //some actions 
     doc.unbind('.dragrotate'); 
    }); 
}); 

为移动浏览器它的工作过程是这样:

holder.bind('touchmove', function(jQueryEvent) { 
//some actions 
}); 

什么是确定移动borwsers的最佳方式? 有没有办法在所有平台上使用相同的功能?

THX

+0

http://stackoverflow.com/questions/3974827/detecting-touch-screen-devices-with-javascript的可能的复制 – 2012-07-05 18:01:18

回答

3

您可以使用navigator.userAgent检查什么浏览器用户使用...下面的代码将是一个很好的起点。

if (navigator.userAgent.match(/Android/i) 
    || navigator.userAgent.match(/iPhone/i) 
    || navigator.userAgent.match(/iPad/i) 
    || navigator.userAgent.match(/iPod/i) 
    || navigator.userAgent.match(/BlackBerry/i) 
    || navigator.userAgent.match(/webOS/i)) { 
    // Mobile browser specific code here 
} 

Detect Mobile Browsers有,如果你想获得更具体的你可以使用一个JS文件。

相关问题