调整大小后更新元素的高度
update height of element after a resize
我如何知道调整大小事件后元素的高度?我使用 jQuery 的函数 .height() 并且在使用调整大小函数之前我有一个 500 毫秒的计时器,但是函数 .height() 仍然是 return 调整大小之前的高度。
$(window).resize(function() {
window.clearTimeout(timerResize);
timerResize = setTimeout(recalculateAll, 1000);
});
function recalculateAll() {
console.log('resize');
setOpenClose('.auteurs .block');
}
function setOpenClose(target) {
$(target).each(function() {
$(this).data('height', $(this).height());
$(this).height($(this).height() - ($(this).find('p').height() + 45));
});
sameHeights(target);
}
function sameHeights(target, locus) {
if (locus === undefined) {
locus = target;
}
var heightMax = 1;
$(target).each(function() {
if ($(this).height() > heightMax) {
heightMax = $(this).height();
}
});
$(target).each(function() {
$(this).height(heightMax);
});
}
希望我的问题是可以理解的,因为我的英语大概,而且我是开发新手。
您应该能够在调整大小回调中调用检索元素的高度。
$(window).resize(function(){
var itemHeight = $('.item').height();
});
我如何知道调整大小事件后元素的高度?我使用 jQuery 的函数 .height() 并且在使用调整大小函数之前我有一个 500 毫秒的计时器,但是函数 .height() 仍然是 return 调整大小之前的高度。
$(window).resize(function() {
window.clearTimeout(timerResize);
timerResize = setTimeout(recalculateAll, 1000);
});
function recalculateAll() {
console.log('resize');
setOpenClose('.auteurs .block');
}
function setOpenClose(target) {
$(target).each(function() {
$(this).data('height', $(this).height());
$(this).height($(this).height() - ($(this).find('p').height() + 45));
});
sameHeights(target);
}
function sameHeights(target, locus) {
if (locus === undefined) {
locus = target;
}
var heightMax = 1;
$(target).each(function() {
if ($(this).height() > heightMax) {
heightMax = $(this).height();
}
});
$(target).each(function() {
$(this).height(heightMax);
});
}
希望我的问题是可以理解的,因为我的英语大概,而且我是开发新手。
您应该能够在调整大小回调中调用检索元素的高度。
$(window).resize(function(){
var itemHeight = $('.item').height();
});