Javascript 根据窗口高度调整容器大小

Javascript 根据窗口高度调整容器大小,javascript,jquery,html,css,Javascript,Jquery,Html,Css,函数resizeGridIscroll(){ var$windowWidth=$(window.width(); var$windowHeight=$(window.height(); var$itemHeight=$('.container').height(); $('.container').css('min-height',$itemHeight-1); } $(窗口)。调整大小(函数(){ resizeGridIscroll(); }) .container{ 最小高度:100vh;

函数resizeGridIscroll(){
var$windowWidth=$(window.width();
var$windowHeight=$(window.height();
var$itemHeight=$('.container').height();
$('.container').css('min-height',$itemHeight-1);
}
$(窗口)。调整大小(函数(){
resizeGridIscroll();
})
.container{
最小高度:100vh;
显示器:flex;
}
.集团{
弹性:1;
}

由于设置了
最小高度
容器的高度将保持在第二次调用
ResizeGridisCroll()

请尝试以下操作:

function resizeGridIscroll(){
  var $windowWidth = $(window).width(),
      $windowHeight = $(window).height(),
      $itemHeight;

  // reset the min-height of .container first
  $('.container').css('min-height', '');

  $itemHeight = $('.container').height();
  $('.container').css('min-height', $itemHeight - 1);
}

不调整浏览器大小时,容器的高度不会收缩。我不理解您的代码。你到底想干什么?这当用户调整导航器的大小时,我希望容器的高度降低。使用我当前的codepen,您可以看到窗口缩小时容器缩小。相反,当它被放大时,容器会继续收缩,而它会增长(在高度上!!),我放弃了。没有道理。为什么只需将
.container
的高度设置为
最小高度
?为什么不使用
$windowHeight
?对不起,我出去了。拿着密码笔或者别管它。我只是在解释我想要的结果,我知道我的代码完全烂了。但是你的哥本在家里什么都不做。就好像js是空的一样。或者我错过了什么。