简体   繁体   English

如何使用phonegap确定屏幕分辨率?

[英]how to determine the screen resolution using phonegap?

I created several images for different screen resolutions. 我为不同的屏幕分辨率创建了几个图像。 With what function fonegap can determine the screen resolution? 什么功能fonegap可以决定屏幕分辨率?

I would also like to see an example. 我还想看一个例子。

You can also use $(window).width() and $(window).height() or screen.width; 你也可以使用$(window).width()和$(window).height()或screen.width; and screen.height; 和screen.height;

Here is an example of this implementation using HTML, Javascript and JQuery mobile. 以下是使用HTML,Javascript和JQuery mobile实现此示例的示例。

HTML PAGE: HTML PAGE:

<html>
    <head>
        <!-- put any jquery references here -->
        <script type="text/javascript" src="index.js">
    </head>
    <body>
        <div id=main_page">
        </div>
    </body>
</html>

Javascript file with JQuery: JQuery的Javascript文件:

$(document).ready(function ()
{
   resolution_handling();
});

function resolution_handling() 
{
    //first way to implement
    browser_width = $(window).width();
    browser_height = $(window).height();
    $("#main_page").css("width":browser_width+"px");
    $("#main_page").css("height":browser_height+"px");

    //second way to implement
    browser_width = screen.width;
    browser_height = screen.height;
    $("#main_page").css("width":browser_width+"px");
    $("#main_page").css("height":browser_height+"px");
}

Both of the implementations will make the div main_page have the dimensions of the screen's height and width. 这两个实现都将使div main_page具有屏幕高度和宽度的尺寸。

I recommend using $(window).width() and $(window).height() as from experience it has been more stable than screen.width; 我建议使用$(window).width()和$(window).height()从经验来看它比screen.width更稳定; and screen.height; 和screen.height;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PhoneGap App上的屏幕分辨率 - Screen Resolution On A PhoneGap App Android Phonegap构建屏幕分辨率问题 - Android Phonegap build screen resolution issue 如何在PhoneGap中获得真实的分辨率? - How to get real resolution in PhoneGap? 将Android大屏幕缩放到iPhone屏幕分辨率和密度(Phonegap Build) - Scale android big screen to iphone screen resolution & density (Phonegap Build) 如何确定一个移动应用程序中可以合理显示多少列? (屏幕尺寸/分辨率/方向) - how to determine how many columns in a mobile app could be rendered reasonably? (screen size/resolution/orientation) 如何使用phonegap确定手机的配置文件(振动/响铃)? - how to determine phone's profile (vibrate/ringing) using phonegap? 使用相同分辨率的Phonegap检测平板电脑或智能手机 - Phonegap detecting tablet or smartphone using the same resolution 使用Phonegap在iOS模拟器上进行分辨率检测 - Resolution detections on iOS Simulator using Phonegap 如何使用PhoneGap停止Playbook上的屏幕旋转? - How can you stop screen rotation on a Playbook using PhoneGap? 如何使用PhoneGap检索设备的屏幕尺寸? - How do you retrieve the screen size of a device using PhoneGap?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM