考虑到jQuery Mobile框架的工作方式,有没有一种方法可以修复网页,使页脚始终与页面底部对齐-无论高度如何。
当前情况下,jQuery页面的高度会发生变化,特别是当设备从纵向旋转到横向时,因此解决方案必须考虑到这一点。
只是为了澄清 - 我不需要将页脚放在视口底部,只是要让默认页面高度不低于视口高度。
谢谢。
考虑到jQuery Mobile框架的工作方式,有没有一种方法可以修复网页,使页脚始终与页面底部对齐-无论高度如何。
当前情况下,jQuery页面的高度会发生变化,特别是当设备从纵向旋转到横向时,因此解决方案必须考虑到这一点。
只是为了澄清 - 我不需要将页脚放在视口底部,只是要让默认页面高度不低于视口高度。
谢谢。
[data-role=page]{height: 100% !important; position:relative !important;}
[data-role=footer]{bottom:0; position:absolute !important; top: auto !important; width:100%;}
现在页面的 data-role 属性已经具有了 100% 的高度,并且页脚位于绝对位置。
此外,Yappo 写了一个非常出色的插件,你可以在这里找到它: jQuery Mobile in a iScroll plugin http://yappo.github.com/projects/jquery.mobile.iscroll/livedemo.html
希望你找到了答案!
答案更新
现在你可以使用 data-position="fixed"
属性来使你的页脚元素保持在底部。
文档和演示:http://view.jquerymobile.com/master/demos/toolbar-fixed/
由于这个问题有些旧,很多事情已经发生了变化。
现在你可以通过将以下内容添加到页脚div中来获得此行为
data-position="fixed"
更多信息请查看: http://jquerymobile.com/test/docs/toolbars/bars-fixed.html
同时请注意,如果你把之前提到的CSS和新的JQM解决方案一起使用,将无法获得适当的行为!
data-position="fixed"
那样一直浮动在所有内容之上....ui-content
{
margin-bottom:75px; /* Set this to whatever your footer size is... */
}
.ui-footer {
position: absolute !important;
bottom: 0;
width: 100%;
}
要在页眉或页脚上启用此行为,请将
data-position="fixed"
属性添加到jQuery Mobile页眉或页脚元素中。
<div data-role="footer" data-position="fixed">
<h1>Fixed Footer!</h1>
</div>
var headerHeight = $( '#header' ).height();
var footerHeight = $( '#footer' ).height();
var footerTop = $( '#footer' ).offset().top;
var height = ( footerTop - ( headerHeight + footerHeight ) );
$( '#content' ).height( height );
body,
.ui-page {
min-height:100% !important;
height:auto !important;
}
.ui-content {
margin-bottom:42px; /* HEIGHT OF YOUR FOOTER */
}
.ui-footer {
position:absolute !important;
width:100%;
bottom:0;
}
这个脚本对我来说似乎有效...
$(function(){
checkWindowHeight();
$(document).bind('orientationchange',function(event){
checkWindowHeight();
})
});
function checkWindowHeight(){
$('[data-role=content]').each(function(){
var containerHeight = parseInt($(this).css('height'));
var windowHeight = parseInt(window.innerHeight);
if(containerHeight+118 < windowHeight){
var newHeight = windowHeight-118;
$(this).css('min-height', newHeight+'px');
}
});
}