我正在构建一个web应用程序,我有一个小屏幕设备和其他大屏幕两套流畅的布局。那么我如何将我的基准放在这两个类别之间呢?我知道如何在js中使用不同的css媒体查询和设备检测技术。
但我想要一个通用的标准来区分这两个类别
例如:我有
var deviceIs = {
android : agent.match(/Android/i),
iPhone : agent.match(/iPhone/i),
iPad : agent.match(/iPad/i),
iPod : agent.match(/iPod/i),
BB : agent.match(/BlackBerry/i),
webOS : agent.match(/webOS/i)
};
var currentRES = {
width : screen.width,
height : screen.height
}但是我想创建一个像这样的对象
var screenTypeis ={
smallScreen : function(){
if(i want this generalized condition){
return true;
}
else{
return false;
}
}}
例如,纵向设备宽度> 480和< 480 &&等...
发布于 2012-07-11 21:14:16
好的,我喜欢的是这样的东西
var screenType = {
isMobileScreen: function () {
if (deviceIs.iPhone || deviceIs.iPod || deviceIs.BB || deviceIs.webOS || deviceIs.mobile || (currentRES.width <= 480 && currentRES.height <= 720)) {
return true;
}
return false;
}
};我还添加了更多的设备列表。
var deviceIs = {
mobile: agent.match(/Android; Mobile|opera mini|opera mobi|skyfire|maemo|windows phone|palm|iemobile|symbian|symbianos|fennec/i),
iPhone: agent.match(/iPhone/i),
iPad: agent.match(/ipad/i),
tab: agent.match(/ipad|android 3|gt-p7500|sch-i800|playbook|tablet|kindle|gt-p1000|sgh-t849|shw-m180s|a510|a511|a100|dell streak|silk/i),
iPod: agent.match(/iPod/i),
BB: agent.match(/BlackBerry/i),
webOS: agent.match(/webOS/i)
};发布于 2012-04-26 15:53:41
谁说什么是小屏幕,什么不是?
例如,新的iPad在尺寸上相当小(与普通屏幕相比),但获得了高分辨率,比高清标准多了100万像素。
就我个人而言,我只会使用CSS媒体查询,因为用户代理字符串无论如何都可以很容易地修改。
发布于 2012-04-26 16:27:26
据我所知,你想要像this这样的东西
function detectDevice(s) {
var userAgent = navigator.userAgent.toLowerCase(),
platform = navigator.platform.toLowerCase();
if (s) {
if (userAgent.match(s.toLowerCase()) != null)
return true;
return false;
}
this.isSmall = function() {
if (screen.width <= 480 && screen.height <= 480)
return true;
return false;
};
this.device = function() {
var a = ["Android", "iPhone", "iPad", "iPod", "BB", "webOS"];
for (var i = 0; i < a.length; i++) {
if (userAgent.match(a[i].toLowerCase()) != null)
return a[i];
}
var a = ["Win", "Mac", "Linux"];
for (var i = 0; i < a.length; i++) {
if (platform.match(a[i].toLowerCase()) != null)
return (a[i] == "Win") ? "Windows" : a[i];
}
return "Unknown Device";
};
this.userAgent = userAgent;
this.platform = platform;
}Example
https://stackoverflow.com/questions/10329248
复制相似问题