- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我试图解决 StackOverflow 问题 yet another HTML/CSS layout challenge - full height sidebar with sticky footer我自己使用 jQuery。因为我的侧边栏可能比主要内容长,所以它与 comment 8128008 的情况相匹配。 .这使得侧边栏比主要内容长并且粘性页脚不可能在缩小浏览器窗口时不会出现问题。
我有一个带有 div
的 html 页面,它会自动拉伸(stretch)以填满屏幕。因此,如果元素下方有空白区域,我会将其向下拉伸(stretch):
但如果浏览器视口(viewport)小于 div
本身,则不会进行拉伸(stretch)但会显示滚动条:
我已将 jQuery 附加到窗口的调整大小事件以调整 div
的大小,如果浏览器窗口不是太小,则在其他情况下删除任何调整大小。这是通过检查视口(viewport)是否高于或小于 document
来完成的。如果视口(viewport)小于 document
,内容似乎大于浏览器窗口,为什么不调整大小;在另一种情况下,我们调整 div
的大小以填充页面。
if ($(document).height() > $(window).height()) {
// Scrolling needed, page content extends browser window
// --> No need to resize the div
// --> Custom height is removed
// [...]
} else {
// Window is larger than the page content
// --> Div is resized using jQuery:
$('#div').height($(window).height());
}
到目前为止,一切运行良好。但是如果我缩小浏览器窗口,在某些情况下,div
应该调整大小但 document
大于 window
的高度,为什么我的脚本假定不需要调整大小并且删除了 div
的调整大小。
实际上,如果我在 bug 出现后使用 Firebug 检查 document
的高度,高度就是应该有的值。所以我想,document
的高度设置有一点延迟。我尝试稍微延迟运行调整大小代码,但没有帮助。
我已经在 jsFiddle 上设置了演示.只需慢慢缩小浏览器窗口,您就会看到 div
“闪烁”。您还可以观察 console.log()
输出,您会注意到,在“闪烁”的情况下,document
的高度和 window
的高度不同而不是相等。
我在 Firefox 7、IE 9、Chrome 10 和 Safari 5.1 中注意到了这种行为。你能证实吗?
你知道有没有修复?还是方法完全错误?请帮助我。
最佳答案
好的——擦掉我的旧答案并替换...
这是你的问题:
您正在获取并比较窗口和文档高度,而没有首先考虑此处的事件顺序。
此时,之前设置的div高度是保持文档高度大于窗口高度,这个逻辑被误解了:“需要滚动,不需要扩展侧边栏”错误地触发
因此抽搐。
为了防止这种情况发生,只需在进行比较之前调整你的 div 和窗口的大小:
(function () {
var resizeContentWrapper = function () {
console.group('resizing');
var target = {
content: $('#resizeme')
};
//resize target content to window size, assuming that last time around it was set to document height, and might be pushing document height beyond window after resize
//TODO: for performance, insert flags to only do this if the window is shrinking, and the div has already been resized
target.content.css('height', $(window).height());
var height = {
document: $(document).height(),
window: $(window).height()
};
console.log('height: ', height);
if (height.document > height.window) {
// Scrolling needed, no need to externd the sidebar
target.content.css('height', '');
console.info('custom height removed');
} else {
// Set the new content height
height['content'] = height.window;
target.content.css('height', height['content']);
console.log('new height: ', height);
}
console.groupEnd();
}
resizeContentWrapper();
$(window).bind('resize orientationchange', resizeContentWrapper);
})(jQuery);
根据 pmvdb 的评论,我将您的 $$ 重命名为“target”
关于javascript - 使用 Javascript 将 div 的大小调整为屏幕高度会在缩小浏览器窗口时导致闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7785691/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在尝试创建一个可以像在 Excel 中一样放大和缩小的 QTableView。 此处提出了类似的问题:Zooming function on a QWidget 但是,我在 PyQt 而不是 C
如图所示。 我在 QScrollArea 中有 QWidget。QWidget 充当细胞图像和一些基于矢量的轮廓数据的渲染小部件。用户可以执行放大/缩小操作,简单地发生的是,它改变了 QPaint
双击 MKMapView 时:放大。 但是如何缩小呢? 最佳答案 总是使用两根手指来放大和缩小。在模拟器上,您需要按住选项键才能在模拟屏幕上显示“两根手指”(我认为这是 Alt 键,但我在 Mac 上
我有一些 javascript for {} 循环,我在整个项目中重复使用它们,它们都类似于: for (var i = 0; i < things.length; i++) { consol
我知道我可以使用C-x C- +进行放大/缩小,但这仅适用于当前文件。一旦我打开另一个文本,文本将恢复为默认值,一遍又一遍地做起来真的很累。如何保持当前emacs session 的全局缩放级别? 如
我对使用编译器工具自动化/简化 Angular 项目感兴趣,这可能适用于其他所有事情,但 Angular 注入(inject)和命名空间很尴尬,足以逃避编译器知识。执行此操作的最佳/专业方法是什么?
有没有办法在emacs上放大和缩小(动态改变字体大小,相当流畅)? 最佳答案 尝试 C-x C-+ 和 C-x C--;即 Control-x Control-减号/Control-再加上。 在一个组
我有一个Windows表单对象,其中包含3个对象,树 View ,richtextbox和tabcontrol。它们没有停靠在Windows窗体中,而是被 anchor 定(顶部+左侧)。 我已经编写
我想向 javascript-mode 添加功能,以便每当我在当前缓冲区上保存 Javascript 文件时,它都会在使用相对路径定义的目录中创建该文件的缩小文件,例如 ../foo 具有相同的文件名
这里有一些关于缩小.war文件的教程,甚至一些帖子。但是,最常见的技术(在Config.groovy中包含grails.war.resources = {})似乎对我不起作用。无论如何,grails会
如何使用 ScaleTransition缩小图像?我现在有这个,它只能放大。如果我误解了该方法,我不会,但我将其从 1 缩放到 0.8。由于某种原因,这种情况仍在扩大。 ScaleTransition
基本上,我想问ReplicaSets是否与CronJobs的suspend: "true"选项类似,但我愿意接受其他建议。 最佳答案 From the official Kubernetes doc
我想使用 boost::polygon 扩展/收缩带孔的多边形。所以澄清一点,我有一个单一的数据结构 boost::polygon::polygon_with_holes_data inPoly 其中
我有一个 map 列表: [%{~D[2019-02-11] => 7}, %{~D[2019-02-12] => 1}, %{~D[2019-02-15] => 1}] 我正在尝试将其变成一张大
我正在制作一个横幅,您可以使用jquery幻灯片功能缩放图像并且可以拖动图像。 除了一件事之外,它工作完美。当您使用图像下方的幻灯片放大图像时,效果非常好。您可以将图像拖动到您想要的位置。但当你想用幻
我们有一个 extjs 应用程序,其中我们布置的结构与 Sencha 推荐的结构不完全匹配。在我们的结构中,我们没有 app.js,但我们有一个 js,其中我们提到了自动加载和启动功能,示例如下以及文
我想在 Chrome/Firefox 中运行的应用程序是: 用 typescript 写 使用 React 使用 es 下一个功能(模块、导入等)编写 有一些导入是纯 js 文件 网页包 3 我可以在
我正在尝试像此处一样应用 Google map 的放大/缩小 - https://www.google.com/maps/@36.241201,-98.1261798,5.13z?hl=en我无法让它
我正在使用 Protractor ,需要缩小到 50%,我尝试了 StackOverflow 上发布的其他几个问题的解决方案,但没有任何效果。其中一些包括: browser.actions().key
我是一名优秀的程序员,十分优秀!