2012-07-05 65 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文件。