【问题标题】:Device width in phonegap androidphonegap android中的设备宽度
【发布时间】:2013-09-06 12:06:20
【问题描述】:

我正在用 phonegap / HTML5 开发一个 android 应用程序。

作为第一步,我正在使用

获取设备的宽度
var viewport = {
        width  : parseInt($(window).width()),
        height : parseInt($(window).height())
    };
alert(viewport.width);

但第一次将其显示 320 部署为警报,但当我重新启动应用程序时,它显示 0。之后经常显示 320(很少见)

如何永久获取设备的实际宽度?

抱歉我的错别字

【问题讨论】:

    标签: android html jquery-mobile cordova


    【解决方案1】:

    你试过了吗

    $(function(){
        document.addEventListener("deviceready", function() {
               var windowWidth = $(window).width();
               var windowHeight = $(window).height();
        });
    });
    

    【讨论】:

      【解决方案2】:

      这个问题不时被提出。请参阅我之前的回答,并阅读博客文章本身:JavaScript+Phonegap+Android: screen.width returns bad (almost random) values

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-28
        • 2017-02-08
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 2014-12-01
        相关资源
        最近更新 更多