我正在使用 AJAX 加载 HTML,在主页中我有两个 div(一个在左侧称为home-logo
,另一个称为home-copy
),AJAX 将加载适合 div 的home-copy
内容,但每个页面的内容不同。如何获取每个内容的高度然后将此高度设置为home-copy.height
?
function handleAjax(e) {
// get the page we want
getPage = $(this).attr('href');
// make AJAX call
$.get('ajax.php', {page: getPage}, function(data) {
result = $.parseJSON(data);
// fill in new page
$('#subnav').html(result.subnav);
$('#home-copy').html(result.copy);
// get document height and get rid of 15% minus the height of the boxes and padding
docHeight = [$(document).height()-($(document).height()*.15)]-100;
// change height of content boxes
$('#home-logo').animate({height: docHeight}, 0);
$('#home-copy').animate({
height: docHeight,
backgroundColor: 'white',
color: 'gray',
paddingTop: 50
}, 0);
// fade out the footer
$('#footer-row').fadeOut();
// change background
//$('#content-area').backstretch(result.background);
$('#background img').attr("src",result.background);
// clear old nav
$('.current_page_item_green').removeClass('current_page_item_green');
$('.current_page_item').removeClass('current_page_item');
// update navigation
if (result.nav_color == 'green') {
// add green
$('.nav-link').each(function() {
$(this).addClass('green');
});
$(result.current_page_item).addClass('current_page_item_green');
} else {
$('.nav-link').each(function() {
$(this).removeClass('green');
});
$(result.current_page_item).addClass('current_page _item');
}
});
}