调整大小和计算高度- bug
Resize and computed height - bugs
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
text-align: center;
}
#prob {
background-color: #F00;
width: 300px;
text-align: center;
line-height: 200px;
display: inline-block;
vertical-align: middle;
}
#prob img {
width: 200px;
height: 150px;
display: inline;
vertical-align: middle;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var img = new Image();
img.src = 'http://galerijauspomena.net76.net/images/10042011744.jpg';
var div = $("#prob").get()[0];
alert($(window).height()); // First showing good height, but few px larger than a page
document.getElementById("cont").style.lineHeight = $(document).height() + 'px';
$(window).resize(
function(){
alert($(document).height()); // On resize down or up, its showing always bigger px, even on Firefox freeze browser!
document.getElementById("cont").style.lineHeight = $(document).height() + 'px';
}
);
div.appendChild(img);
});
</script>
</head>
<body>
<div id="cont"> <!-- nbsp in order to line-height to work. Is it any way without it? -->
<div id="prob"> </div>
</div>
</body>
</html>
调整大小后,我发现计算的高度总是更大,尽管我调整大小。我犯了什么错误吗?
另外,在调整大小时,Firefox会自动冻结…
如果我理解你想做什么,你想使用$(window).height()
而不是document
。问题是,增加行高会增加文档的大小,这又会增加行高,增加文档大小,等等。所以它会越来越大
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 查找元素高度,包括边距
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 通过jquery设置最小高度
- 文档就绪提供了错误的选择器高度
- 调整缩放窗口高度提升缩放
- 根据图像高度添加类
- 检测非移动页面上的移动设备屏幕宽度和高度
- 更改代码镜像中TextArea的高度和宽度
- 获取iframe内容的宽度-高度
- 在android中显示固定高度的webview内的大型内容
- 调整大小和计算高度- bug