2012-04-01 39 views
0

我想要的是一个动画的div,它将在300px和100%的窗口高度减去26 px之间切换高度。我面临的问题是,在窗口调整大小后,div不会更新它的扩展大小。我总是希望它扩展到windowheight-26px,但现在它只能切换到第一个窗口高度,它不会更新。我现在所拥有的代码是:jQuery更新切换功能的变量,在窗口调整大小

$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

我将在toggleHeaderDown计算$ NH:

function toggleHeaderDown() { 
     $nh = $j(window).height() - 26; 
     // ... 
} 

这样,你不需要等待resize事件得到高度的正确值

+0

啊当然,我是多么的愚蠢啊!非常感谢,它做到了 – 2012-04-02 06:40:12