2012-05-31 78 views
0

我使用以下函數根據窗口高度給出div的高度值。但對於非常小的屏幕,我想添加400px的最小高度。因此,對於窗口的高度jquery和css的最小高度

$('.info').height(function(){ 
     return $(window).height() * 0.7; 
    }); 

小於630像素給.info類400像素的高度值。

任何幫助將是偉大的。

編輯:

如果窗口小於630像素這個高度添加到它的CSS:

.info {height:400px;} 

否則找到*窗口高度的0.7和使用。

+0

實際上你想要做什麼? –

回答

0

試試這個,但你應該檢查窗口的高度,首先要確保它的價值增加

var windowh=$(window).height()* 0.7; 
$('.info').height(windowh); 
0
$('.info').height(function(){ 
     if($(window).height() <= 630) 
     { 
      return ($(window).height() * 0.7) + 400; 
     } 

     return ($(window).height() * 0.7) 

}); 
1
$('.info').css('min-height', function(){ $(window).height() * 0.7 }); 

試試這個它會工作.....

0

使用Math.max函數。

$('.info').height(function(){ 
    return Math.max($(window).height() * 0.7, 400)+'px'; 
});