如何识别屏幕尺寸 [英] How to identify screen size

查看:142
本文介绍了如何识别屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些移动Web应用程序(我的第一时间),但我遇到了这样的问题:尽管使用了特殊的移动框架,但某些尺寸的模态窗口在小屏幕上还是不正确的.例如,我有一个ipod和ipad:

I am working on some mobile web application (it my firs time) and I faced such problem: despite the use of special mobile frameworks some sizes of modal windows are not correct on small screens. For example i have an ipod and ipad:

在iPod上,按钮的大小已经改变了一点.因此,可能有任何方法可以使用js识别屏幕尺寸类似类别(小,正常,大,或者只是获取阵列的尺寸列表),然后基于此在源代码中进行一些基本更改.

On iPod the size of buttons is already changed for a bit. So, may be there is any way to identify screen size like category (small, normal, large or may be just get list of sizes to the array) using js may be and then based on it i would do some basic changes in the source.

推荐答案

使用jquery查找当前窗口宽度

use jquery to find current width of window

$(function() {
    showWidth($(this).width());
    $(window).resize(function() {
        showWidth($(this).width());
    });
});

function showWidth(wid) {
     var width = parseInt(wid);
     if (width < 1440) {
        //use wider stylesheet
    } else if ((width >= 901) && (width < 1440)) {
        //use wide stylesheet
    } else {
        //use small stylesheet
    }    
}

这篇关于如何识别屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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