1

我是 jquery mobile 的新手。我正在编写一个移动应用程序,我希望它能够动态地适应data-role="page" 所有设备上的屏幕大小的内容。什么是有效的方法?我读到了必须在标题中设置的视口。它在调整页面的高度和宽度时起什么作用?

谢谢你。

4

1 回答 1

3

这是一个 jsFiddle:http: //jsfiddle.net/ezanker/Tx4kF/

在 Ved 提到的元视口之后,使用 javascript 计算内容窗格的可用高度:

function ScaleContentToDevice() {
   scroll(0, 0);
   var headerHeight = $("#jqmHeader:visible").outerHeight();
   var footerHeight = $("#jqmFooter:visible").outerHeight();
   var viewportHeight = $(window).height();

   var content = $("#jqmContent:visible");
   var contentMargins =  content.outerHeight() - content.height();

   var contentheight = viewportHeight - headerHeight - footerHeight - contentMargins;

   content.height(contentheight);
}

这假设您在 body/html 上没有边距或填充:

html, body {
   margin: 0;
   padding : 0;
}

对 pageshow 事件执行缩放以及方向更改/调整大小。

$(document).on("pageshow", function(){
   ScaleContentToDevice();
});
$(window).on('resize orientationchange', function(){ ScaleContentToDevice() });
于 2013-10-25T18:55:30.347 回答