【发布时间】:2014-03-02 00:17:55
【问题描述】:
我正在开发一个看起来像是在 iPad 上运行的移动应用程序。当页面最初加载时,如果页面主体超出窗口/屏幕大小,页面的滚动条会显示在页眉和页脚“上方”。但是刷新页面后,滚动条会出现在页眉和页脚之间(也就是只在正文上方),这就是我想要的。
我无法在 jsfiddle 上复制确切的行为(滚动条仅在刷新后显示在正文上),但它至少向您显示了整个页面上的滚动条。
感谢任何帮助...
这是我拥有的代码: CSS:
.locationListItem {
margin-bottom: 5px;
}
.locationListPrimary {
color: blue;
font-weight: bold;
font-size: medium;
}
.locationListSecondary {
font-weight: bold;
font-size: smaller;
}
HTML:
@section header {
@*
Recommeneded to use an h1 element, but can contain any kind of element, but make sure to add the TrailsHeaderPrimary class to get the proper styling...
Using an h1 element will get the proper padding around the header line. To see the difference, try doing an h1 vs p *@
<h1 class="testHeaderPrimary">Search Locations</h1>
}
<div style="top: 15px; left: 15px; width: 100%; z-index: 2">
<ul data-role="listview" data-filter="true" data-filter-placeholder="Search/Filter Locations...">
@foreach (var location in Model.AvailableLocations)
{
<li>
<a href="#">
<div class="ui-grid-b">
<div class="ui-block-a"><span class="locationListPrimary" style="width: 20%">@location.Thing</span></div>
<div class="ui-block-b"><span class="locationListPrimary" style="width: 20%">@location.Person</span></div>
<div class="ui-block-c"><span class="locationListSecondary" style="width: 60%">@location.Year | @location.Stuff | @location.Type</span></div>
</div>
</a>
</li>
}
</ul>
</div>
@section navBar1 {
<a href="/Search/Index" style="font-size: x-large">Search</a>
}
@section navBar2 {
<a href="/Location/Index" style="font-size: x-large">Location</a>
}
@section navBar3 {
<a href="/LocationStrip/Index" style="font-size: x-large">LocationStrip</a>
}
@section navBar4 {
<a href="http://stackoverflow.com/" style="font-size: x-large; height: 60px" target="_blank">StackOverflow</a>
}
@section navBar5 {
<a href="#" style="font-size: x-large" target="_blank">NA</a>
}
Javascript(来自布局):
$(document).ready(function () {
resetScreenSize();
});
$(window).resize(function () {
resetScreenSize();
});
var resetScreenSize = function () {
var windowHeight = $(window).height();
var header = $('#testHeader');
var headerHeight = header.outerHeight();
var footer = $("#testFooter");
var footerHeight = footer.outerHeight() - 1;
$(".ui-grid-a").height(windowHeight - footerHeight - headerHeight);
$("#panelMain").height(windowHeight - footerHeight - headerHeight);
};
更新 1: 这是布局文件中的正文...
<body style="height: 100%">
<div id="main" role="main" class="ui-content jqm-content" style="padding: 0; height: 100%;">
<div id="testHeader" data-role="header" data-theme="b" data-position="fixed">
@RenderSection("header", false)
</div>
<div class="ui-grid-a" data-theme="a">
<div id="panelMain" style="overflow: auto;">
<div class="ui-content">
@RenderBody()
</div>
</div>
</div>
<div id="testFooter" data-role="footer" data-theme="b" data-position="fixed" data-tap-toggle="false" style="height: 60px; display: block;">
<div data-role="navbar">
<ul>
<li>@RenderSection("navBar1", true)</li> <!-- Home/1 should be reserved for the home screen -->
<li>@RenderSection("navBar2", true)</li>
<li>@RenderSection("navBar3", true)</li>
<li>@RenderSection("navBar4", true)</li>
<li>@RenderSection("navBar5", true)</li>
</ul>
</div>
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
更新 2: 底部的一个选项卡转到一个页面,它被分成 20%/80%。该页面使用不同的布局来执行 20/80。当该页面首次加载时,它不会将我的样式合并到如下所示的“head”标签中:
#panelLeft {
width: 20%;
border-right: 3px solid
}
#panelMain {
width: 80%;
}
但是一旦我刷新页面,所有的样式都会被应用。我开始怀疑它是否没有应用我在布局页面的每个“head”标签中指定的自定义样式。我应该将它们放在单独的 css 文件中吗?
【问题讨论】:
-
这个问题不再需要,因为项目正在转换为 Angular SPA。我没有机会尝试建议的答案。
标签: javascript jquery html css layout