- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我创建了一个带有固定页眉和侧边栏的页面模板。为了克服 position:fixed
的缺点,我添加了一些 JavaScript 以在窗口宽度低于 1000px 时将其更改为 position:absolute
并在达到或超过 1000px 时再次返回.
它工作正常,除了在 IE8 和 IE9 中,它们使标题向右跳到垂直滚动条宽度的一半。这是因为 $(document).width()
在 IE8/9 中包含滚动条,而在 Chrome 和 Firefox 中不包含滚动条。
在另一篇文章中,一个建议是将 $(document).width()
替换为 $('body').attr('clientWidth')
。这在我的情况下不起作用,因为我使用的是固定/绝对(取决于窗口的宽度)定位。
JSFiddle 在这里:http://jsfiddle.net/AUfHW/
代码如下:
<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
var CONTENT_WIDTH = 1000;
var windowWidth;
function updateHeaderWidth(){
$('#headerBarWrapper').width(windowWidth < CONTENT_WIDTH ? $('body').attr('clientWidth') : '100%');
}
function addAbsoluteLayout(){
$('#headerBarWrapper,#leftSidebar,#rightSidebar').addClass('absolute');
}
function removeAbsoluteLayout(){
$('#headerBarWrapper,#leftSidebar,#rightSidebar').removeClass('absolute');
}
// Handle a window resize event, adjusting the positioning of the header and sidebars and maintaining the header width.
$(function(){
windowWidth = $(window).width();
if (windowWidth < CONTENT_WIDTH) {
addAbsoluteLayout();
updateHeaderWidth();
}
$(window).resize(function(){
if (windowWidth >= CONTENT_WIDTH && $(window).width() < CONTENT_WIDTH) {
addAbsoluteLayout();
}
else if (windowWidth < CONTENT_WIDTH && $(window).width() >= CONTENT_WIDTH) {
removeAbsoluteLayout();
}
windowWidth = $(window).width();
updateHeaderWidth();
});
});
//]]>
</script>
<style type="text/css">
/* Global fonts and colors */
html,body,input,select {
font: 11px 'lucida grande',tahoma,verdana,arial,helvetica;
color: #444;
background-color: #fcfcfc;
}
/* Layout */
html,body {
margin: 0;
padding: 0;
}
html {
overflow-y:scroll;
}
#headerBarWrapper {
border-bottom:1px solid #222;
-webkit-box-shadow:0 0 2px rgba(0,0,0,.52);
height:37px;
position:fixed;
left:0;
top:0;
width:100%;
background-color:#636363;
z-index:300;
}
#header {
width:980px;
height:37px;
margin:0 auto;
color:white;
padding:0 10px;
}
#headerLeft {
float:left;
}
#headerRight {
float:right;
}
#leftSidebar {
width:200px;
min-height:10px;
position:fixed;
}
#rightSidebar {
width:200px;
min-height:10px;
position:fixed;
margin-left:780px;
}
#contentWrapper {
width:100%;
margin-top:37px;
}
#contentOuter {
width:980px;
margin:0 auto;
padding-bottom:24px;
padding-left:10px;
padding-right:10px;
}
#contentShell {
width:778px;
margin-left:200px;
border-left:1px solid #ddd;
border-bottom:1px solid #ddd;
border-right:1px solid #ddd;
overflow:auto;
}
#content {
width:564px;
margin:8px 200px 0 0;
padding:0 8px 8px 8px;
min-height:500px;
}
#footer {
width:580px;
margin:0 200px;
padding-top:4px;
padding-bottom:24px;
}
.absolute {
position:absolute !important;
}
</style>
</head>
<body>
<div id="headerBarWrapper">
<div id="header">
<div id="headerLeft">Left stuff here</div>
<div id="headerRight">Right stuff here</div>
</div>
</div>
<div id="contentWrapper">
<div id="contentOuter">
<div id="leftSidebar">
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
<p>Left sidebar</p>
</div>
<div id="rightSidebar">
<p>Right sidebar</p>
<p>Right sidebar</p>
<p>Right sidebar</p>
<p>Right sidebar</p>
<p>Right sidebar</p>
<p>Right sidebar</p>
<p>Right sidebar</p>
</div>
<div id="contentShell">
<div id="content">
<h3>The standard Lorem Ipsum passage, used since the 1500s</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<h3>Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</h3>
<p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</p>
<h3>1914 translation by H. Rackham</h3>
<p>"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"</p>
<h3>Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</h3>
<p>"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</p>
<h3>1914 translation by H. Rackham</h3>
<p>"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
</div>
</div>
<div id="footer">
Footer
</div>
</div>
</div>
</body>
</html>
最佳答案
这对你有帮助吗?
function getDocWidth() {
var D = document;
return Math.max(
Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
Math.max(D.body.clientWidth, D.documentElement.clientWidth)
);
}
关于html - IE8文档宽度包括滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8648923/
127.0.0.1:8000/api/仅包含来自第二个应用程序的 url,但我将两个 url 模块链接到相同的模式。甚至有可能做到这一点吗? 第一个应用程序: from django.urls imp
我目前正在学习 ColdFusion。我有 PHP 背景,对此我有点困惑。 我有一个选择菜单,我希望将选项保存在不同的文件中。 (例如 options.cfm)当我调用文件时,我想在选择菜单中包含选项
字符串: "75,000", "is", "95%", "or", "95/100" "of", "monthly", "income" o/p: "is","%, "or", "/", "of",
我有 4 个 javascript 文件(每个文件对应一个 HTML 文件),所有 4 个文件中的 3 个函数都是相同的。我想找到一个顺利的解决方案,我可以以某种方式分别包含这 3 个函数...是否可
我在 PHP 中有这种情况,其中 include在一台服务器上被遗漏,但在另一台服务器上没有(我没有设置服务器,所以我不能告诉你更多;我不是真正的 devops 人,所以这就是我在这里问的原因)。两台
这是一个模式文件,midi.xsd定义类型,note ,用于存储 MIDI 音符值: 这是另一个模式文件,octaves.xsd使用
我想备份以下文件夹 /home /etc /usr/local /root /var /boot 并排除 /var/tmp /var/run /var/lock /home/*/.thumbnails
如何重新编码具有许多值(包括缺失值)的数值变量,以获得数字 0:n-1哪里n是唯一值的数量,包括 NA ,整齐? 例子: df 1 1000 0 2 1000 0 3 N
选择元素的 html(包括在内)的最佳方法是什么?例如: This is just a test. 而$('#testDiv').html()返回"This is just a test."
我正在尝试设置Varnish来处理本地环境中的ESI包含。 我在虚拟机中运行 Varnish ,内容在主机上运行。 我有两个文件“index.html”和“test.html”。它们都存储在apach
我有以下内容,并且想要检索“ FromEmail”不为空的数据 Simple email@gma
欧海,我正在编写一个小型 PHP 应用程序,使用一个单独的 config.php 文件和一个functions.php,其中包含我将在应用程序中使用的所有自定义函数。现在,我真的必须在每个函数中包含
我知道可以将 JavaScript 放在一个特定的 .js 文件中,然后通过执行以下操作将其包含在任何页面中...... 我注意到,对于包含的这些 .js 文件: 它们实际上不必以 .js 结尾 其
我使用 gwt UIBinder 添加了一些项目到我的 ComboBox。 --select one-- Dispute Referral Form Dispute Settlement Clause
我可以将一个 first.c 文件包含到另一个 second.c 中吗? (我正在做一些套接字编程,以将服务器收到的消息存储在链接列表中,因此在第一个程序中,我尝试保留链接列表和第二个程序套接字编程文
我有一个简单的 Spring MVC 数据项目设置,我试图选择 Admin 中尚不存在的用户列表。 table 。这是我的存储库方法 SELECT u FROM User u WHERE u.id N
在 bash 脚本中,使用什么实用程序以及如何删除两个字符串之间的文本,包括字符串。 原文: (ABC blah1)blah 2(def blah 5)blah 7)(DEF blah 8)blah
我有这个 BST 问题,我试图用 Java 解决,但我不知道为什么它不起作用。问题是: 二叉搜索树 (BST) 是一种二叉树,其中每个值节点大于或等于该节点的所有节点中的值左子树并且小于该树中所有节点
我有一个字符串,其中包含“Dollars”和“Cents”符号。我想删除它们。我试过了 string.replaceAll("[\"\\u00A2\" $]", "") 但它不起作用。正确的做法是什么
我在 stories 和 tags 之间有一个多对多的关系,为保存关系而创建的表是 taxonomies。我想搜索所有具有所有给定标签的故事。 到目前为止我使用的查询是这个,当然它对我不起作用,它返回
我是一名优秀的程序员,十分优秀!