我想要的是一个动画div,它将在窗口高度减去26像素的300px和100%之间切换高度。我面临的问题是,在窗口调整大小后,div不会更新它的扩展大小。我总是希望它扩展到windowheight-26px,但是现在它只切换到第一个窗口高度,它不会更新。我现在的代码是:
$j(document).ready(function(){
var $nh = $j(window).height()-26;
$j("#header-wrap").toggle(function(){
toggleHeaderDown($nh);
},function(){
toggleHeaderUp();
});
function toggleHeaderDown(y){
$j("#header-wrap").animate({height:y},400,'easeInOutQuart');
$j("#header-image").animate({height:'100%'},400,'easeInOutQuart');
$j("#head1, #head2, #head3, #head4").animate({top: 0},400,'easeInOutQuart');
};
function toggleHeaderUp(){
$j("#header-wrap, #header-image").animate({height:300},400,'easeInOutQuart');
$j("#head1").animate({top: -50},400,'easeInOutQuart');
$j("#head2").animate({top: -370},400,'easeInOutQuart');
$j("#head3").animate({top: -200},400,'easeInOutQuart');
$j("#head4").animate({top: -330},400,'easeInOutQuart')
};});
$j(window).resize(function() {
$nh = $j(window).height()-26;
});
答案 0 :(得分:0)
我会在toggleHeaderDown计算$ nh:
function toggleHeaderDown() {
$nh = $j(window).height() - 26;
// ...
}
这样您就不需要等待resize事件来获得正确的高度值