2013-10-25 67 views
1

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

谢谢。

+2

添加在标头标记 和阅读这个链接1)http://view.jquerymobile.com/1.3.2/dist/demos/widgets/pages/ – Ved

回答

3

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

由韦达提到的中继检视后,使用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() }); 
+0

视口描述说,在标题中设置视口会自动处理高度和宽度。但它不起作用。那么它的实际意义是什么? – sonam

+1

元标记不处理设置HTML元素高度以填充屏幕,而是帮助确定页面在移动设备上的显示方式:应该缩小到适合的范围,还是应该只是部分可见等。请参阅http://www.javascriptkit.com/dhtmltutors/cssmediaqueries3.shtml了解更多信息。我的回答假设你试图让内容div完全填充页面的可用高度,也许这不是你正在寻找的... – ezanker

+0

它对我来说非常好。但这在iPad上不起作用。如果我在这种情况下更改方向,则会显示放大页面并且不适合页面。 – sonam