【发布时间】:2011-01-18 12:30:27
【问题描述】:
我正在使用 jQuery Mobile 制作网站。
如何保持 jquery 移动页眉和页脚固定?我只想滚动内容(就像在 iPhone 应用程序中发生的那样),并保持页眉和页脚固定在顶部和底部。
有什么建议吗?
【问题讨论】:
我正在使用 jQuery Mobile 制作网站。
如何保持 jquery 移动页眉和页脚固定?我只想滚动内容(就像在 iPhone 应用程序中发生的那样),并保持页眉和页脚固定在顶部和底部。
有什么建议吗?
【问题讨论】:
将此属性添加到您的页眉/页脚 div:
<div data-role="header" data-position="fixed">
<h1>Header Page 1</h1>
</div>
另外,你可以看看这个: http://jquerymobile.com/test/docs/toolbars/footer-persist-a.html
【讨论】:
data-position="fixed" 得到的结果……好坏参半。使用 here 找到的视口标签后效果更好——不是基于头脑的花哨的 JS!,但它仍然不是 100%。这是在 2013 年。
我在使用 jquery mobile 时遇到的问题是页眉和页脚褪色。我想这是他们将来会纠正的事情,但除了 Dan 建议的 iscroll 之外,还有 jquery mobile scrollview 和 wink 工具包。我使用 jquery mobile scrollview 取得了不错的效果,但使用 iscroll 或 wink 没有运气
1) Jquery 移动滚动视图
2) 眨眼工具包
【讨论】:
另一个选项是查看 iScroll:http://cubiq.org/iscroll
【讨论】:
要启用此工具栏功能类型,请将 data-fullscreen="true" 属性和 data-position="fixed" 属性应用于页眉和页脚 div 元素。该框架还将取消设置内容容器(ui-content)的填充
<div data-role="header" data-position="fixed" data-fullscreen="true">
<h1>Header Page 1</h1>
</div>
【讨论】:
另一种方法是使用http://jquerymobile.com/test/experiments/scrollview/scrollview-direction.html(jquery.mobile.scrollview.js、scrollview.js 和 easing.js)并将 data-scroll="true" 放入页面 div 标签中,如下所示:scrollview for jQuery mobile tollbars *not* to be fixed .
到目前为止对我来说效果很好。
干杯,
E
【讨论】:
使用 iScroll v4。保持页眉和页脚固定,只滚动内容。 iScroll 需要一个包装器 DIV 和子元素。在下面的示例中, content_items 是包含要滚动的项目的子 div。我注意到您不能将 iScroll 的 data-role="content" 和包装器 DIV 组合在一个 HTML 元素中!。
<script type="text/javascript">
var myScroll;
$(document).ready(function () {
myScroll = new iScroll('wrapper');
});
</script>
<div data-role="page">
<div id="header" data-role="header" data-position="fixed"></div>
<div id="content" data-role="content" class="contentcontainer contentsearched">
<div id="wrapper">
<div id="content_items" class="content_items"></div>
</div>
</div>
<div id="footer" data-role="footer" data-position="fixed">
<div data-role="navbar"></div>
</div>
</div>
【讨论】:
我建议您尝试最新的 jquery-mobile 版本 (1.1.0-rc)。它修复了这个错误。
看看here
【讨论】:
对于 iOS 6、7 和 8,此 hack 似乎可以解决问题并触发重绘以正确替换 iPod、iPhone 和 iPad 上的固定标题(带或不带面板)。注意:我们针对 iOS 设备进行测试,仅在这种情况下添加此事件 *。
if (iOS()) {
$(document).on('blur', 'input:not(:submit), select, textarea', function () {
var paddingBottom = parseFloat($(".ui-mobile-viewport, .ui-page-active").css("padding-bottom"));
$(".ui-mobile-viewport, .ui-page-active").css("padding-bottom", (paddingBottom + 1) + "px");
window.setTimeout(function () {
$(".ui-mobile-viewport, .ui-page-active").css("padding-bottom", paddingBottom + "px");
}, 0);
});
}
* iOS 测试:
var iOS() = function () {
var userAgent = window.navigator.userAgent.toLowerCase();
return (/iphone|ipad|ipod/).test(userAgent);
}
【讨论】: