获取我的设备的宽度和高度,并将它们注入到我的css样式中

get the width and height of my device and inject them into my css style

本文关键字:我的 注入 css 样式 高度 获取      更新时间:2023-09-26

我正试图通过编程在Phonegap/JQuery mobile中找到设备宽度,并在修改后将其注入到我的css样式中。

这是我试图根据设备的高度和宽度来更改元素"包装器"的高度的css代码

#wrapper {
    width: 310px;
    height: 400px;
    float: left;
    position: relative; /* On older OS versions "position" and "z-index" must be defined, */
    z-index: 1; /* it seems that recent webkit is less picky and works anyway. */
    overflow: hidden;
    background: #ffffff;
}

有人知道它是怎么工作的吗?感谢

$(window).resize(function() {
  // This will execute whenever the window is resized
  $(window).height(); // New height
  $(window).width(); // New width
});

$(document).ready(function()中的调用事件

jQuery.event.add(window, "resize", resizeFrame);    

这是功能:

function resizeFrame() {
var newHeight = $(window).height();
var newWidth = $(window).width();
$('#wrapper').width(newWidth);
$('#wrapper').height(newHeight);
}