[英]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.