我想设置div#顶部高度等于图像高度。我写道:在文档加载时获取图像高度
$(document).ready(function() {
setTopHeight();
});
/*
* window resizing
*/
$(window).resize(function() {
setTopHeight();
});
/*
* setting #top height by banner height
*/
var setTopHeight = function() {
var bannerHeight = $('#banner-image').height();
$('#top').height(bannerHeight + 'px');
};
它适用于调整大小,但不重新加载。我试过这样:
$(document).ready(function() {
setTimeout(function() {
setTopHeight();
}, 50);
});
它的工作原理,但它当然不是解决方案。有人可以告诉我为什么console.log返回0吗?
$(document).ready(function() {
console.log($('#banner-image').height());
});
是banner-image img标签的id或它的图像包装div ID? – 2013-03-20 10:57:36