我有一些 Jquery 滚动条。
对于桌面浏览器,我使用这种结构:
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
});
确定移动浏览器的最佳方法是什么?
有没有办法在所有平台上使用相同的功能?
谢谢
最佳答案
您可以使用 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 文件,如果您想获得更具体的信息,可以使用它。
关于Jquery - 检测移动浏览器的最佳方法? (鼠标按下/触摸移动),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11349849/