Android-Phonegap设备宽度获取不同值
我正在用phonegap android开发一个应用程序 我正在尝试准备好设备上的设备宽度。我试过这个密码 当应用程序第一次开始提供(480,我使用的是三星i9003)宽度(警报)时,当我点击backbutton并再次运行应用程序时,显示320 我在这里被绊倒了。。请帮忙Android-Phonegap设备宽度获取不同值,android,jquery,cordova,jquery-mobile,Android,Jquery,Cordova,Jquery Mobile,我正在用phonegap android开发一个应用程序 我正在尝试准备好设备上的设备宽度。我试过这个密码 当应用程序第一次开始提供(480,我使用的是三星i9003)宽度(警报)时,当我点击backbutton并再次运行应用程序时,显示320 我在这里被绊倒了。。请帮忙 <!DOCTYPE HTML> <html> <head> <head> <meta http-equiv="Content-Type" conte
<!DOCTYPE HTML>
<html>
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<meta name="viewport" content="width=device-width; user-scalable=no" />
<link rel="stylesheet" href="css/jquery.mobile-1.1.1.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Title</title>
</head>
<body onload="onLoad()">
<div class="logo"></div>
<div class="content">
<div id="justt"></div>
</div>
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
var width=0;
width=$(window).width()
$('#justt').css('width',(width)+'px');
alert(width);
}
</script>
</body>
</html>
标题
函数onLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
函数ondevicerady(){
var宽度=0;
宽度=$(窗口)。宽度()
$('#justt').css('width',(width)+'px');
警报(宽度);
}
为什么不尝试获取页面内容宽度:
var screenWidth = 0;
$(window).bind('resize', function () {
screenWidth = $('[data-role="page"]').first().width());
}).trigger('resize');
这将为您提供页面内容宽度,即使页面大小已调整
获取视口屏幕尺寸($(window).width())时,您不会总是获得完美的结果,不同的设备表现不同
$(window).width()和$(window).height()将为您提供视口尺寸,而不是屏幕尺寸。您将看到此问题的详细概述。如果您试图创建一个要根据移动窗口设置的div,您可以jQuerymobile.js根据移动窗口创建一个具有不同功能的div。您好,感谢您的回复并根据您的评论进行设置,然后放置一个主div(名为“.main”)在javascript中取其宽度,但第一次为480px。当我关闭应用程序并重新打开它的“320px”时,我的代码像var width=$('.main').css('width');警报(宽度);我不是一个css的人,如果你告诉我你想从这个功能中获得什么,我可以建议更多的答案。