如果已将类添加到主屏幕,例如在 iPhone 上,是否可以将类添加到 webapp。
这样我就可以在主屏幕版本中显示某些内容,而不是在网站上显示。
这必须使用服务器端代码来完成还是可以使用 jQuery 来完成?
Modernizr根据可用的功能将一堆类添加到文档的 html 中。我不记得它是否会检测到 iOS(我怀疑不会),但它会告诉你是否有触摸屏要处理。
您可以通过检测设备尺寸来确定是否是小屏幕设备,或者您可以尝试检测正在访问的设备类型。
为了检测设备的分辨率,您可以使用 Javascript(或 jQuery)甚至 CSS 3 使用@media
查询。
jQuery 示例:
var windowsWidtdh = $(window).width();
var windowsHeight = $(window).height();
CSS 3 媒体查询:
/* Hidden the mobile extra info for desktop computers */
#mobileInfo{
display:none;
}
/*Showing the mobile info for screen resolutions smaller than 640px*/
@media only screen and (max-width: 640px) {
#mobileInfo{
display:block;
}
}