使用 Modernizr 测试平板电脑和移动设备 - 需要意见 [英] Using Modernizr to test for tablet and mobile - Opinions wanted

查看:17
本文介绍了使用 Modernizr 测试平板电脑和移动设备 - 需要意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Modernizr 来检测用户是在台式机、平板电脑还是移动设备上查看网站.

我最初的想法显然是检查屏幕尺寸是否足以满足移动设备和大型台式机的需求.对于屏幕尺寸也可能等于小桌面屏幕 (1024 x 768) 的平板设备,我也会测试触摸事件.

此时我想专注于移动/平板设备,正如 jQuery mobile 所说,A 级.我不希望利用任何特定的移动设备功能,只是检测台式机、平板电脑或移动设备,然后根据测试结果附加 CSS 类,为每个功能提供量身定制的 UI.

您认为这足以达到我想要的效果还是您认为我应该测试其他功能?非常感谢.

解决方案

Modernizr 可以检查触摸事件>

为了测试设备是平板电脑、手机还是台式机,我可能更倾向于使用用户代理.查看 DetectMobileBrowsers.com

上的脚本

Modernizr 只是测试浏览器是否支持某些功能.据我所知,它似乎没有测试 browser_type == mobile 和这些方面的东西......

请记住,如今很多现代台式电脑都配备了触摸屏,因此即使检测到触摸支持也不能保证它是移动设备或平板电脑.

I want to use Modernizr to detect whether a user is view a site on a desktop, tablet or mobile device.

My initial first thoughts are obviously to check screen sizes that should be enough for mobile devices and also for larger desktops. For tablet devices where the screen size could also equal that of a small desktop screen (1024 x 768) I would test for touch events as well.

At this time I would like to focus on mobile/tablet devices that, as jQuery mobile puts it are, A-grade. I am not looking to tap in to any specific mobile device features simply detect desktop, tablet or mobile and serve up a tailored UI for each by appending CSS classes depending on the results of the test.

Do you think this is enough to achieve what I want or do you think I should be testing for other capabilities? Many thanks in advance.

解决方案

Modernizr can check for touch events

For testing whether the device is a tablet or phone or desktop, I would probably lean more toward using User Agents. Take a look at the scripts on DetectMobileBrowsers.com

Modernizr simply tests for whether or not a browser supports certain features. As far as I know, it doesn't appear to test browser_type == mobile and stuff along those lines...

Keep in mind that a lot of modern desktop PCs these days have touch screens, so even detecting touch support does not guarantee that it is a mobile device or tablet.

这篇关于使用 Modernizr 测试平板电脑和移动设备 - 需要意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆