页面加载 jQuery 后匹配 div 高度
加载图像后,我无法匹配 div 的高度。它获取最高 div 的高度,但似乎在加载图像之前就获取了它。有什么办法解决这个问题吗?这是我到目前为止所拥有的:
function matchColHeights(col1, col2) {
var col1Height = $(col1).height();
alert('col1 '+col1Height);
var col2Height = $(col2).height();
alert('col2 '+col2Height);
if (col1Height < col2Height) {
$(col1).height(col2Height);
} else {
$(col2).height(col1Height);
}
}
$(document).ready(function() {
matchColHeights('#leftPanel', '#rightPanel');
});
这是运行位置的链接: http://www.tigerstudiodesign .com/blog/
I am having trouble matching the height of a div after the loading of images. it gets the height of the tallest div, however it seems to get it before the images are loaded. is there any way around this? here is what I have so far:
function matchColHeights(col1, col2) {
var col1Height = $(col1).height();
alert('col1 '+col1Height);
var col2Height = $(col2).height();
alert('col2 '+col2Height);
if (col1Height < col2Height) {
$(col1).height(col2Height);
} else {
$(col2).height(col1Height);
}
}
$(document).ready(function() {
matchColHeights('#leftPanel', '#rightPanel');
});
here is a link to where it is being ran: http://www.tigerstudiodesign.com/blog/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
图像加载后是否调整列高。像这样的东西:
Do the column height resize after the image has loaded. Something like:
根据 这个问题,
window.load
在加载所有图像时触发,因此请尝试以下操作:According to this question,
window.load
is fired when all images are loaded, so try this:问题是图像标签上未提供宽度和高度。 DOM 使用它们进行测量,如果未提供它们,则必须等待图像加载才能以正确的高度“重新绘制”屏幕。这就是为什么它不起作用..
The issue is when the width and the height are not provided on the images tags. The DOM uses them to measure, if they aren't provided then it has to wait for the image to load in order to "re paint" the screen with the correct heights. This is why it wasn't working..