Jquery 变量使用 window.innerHeight 返回为未定义

Jquery variable using window.innerHeight comes back as undefined

我正在尝试根据 window 的宽度设置 div 的高度。 vh 单位不会因为 iOS 移动问题。我的代码基于这个相关的 Stack Overflow 答案:,它按预期工作,不断更新身高。出于某种原因,每当我尝试将其应用于另一个元素 (.nav-main) 时,控制台 returns undefined.

$(document).ready(function () {

    function resetHeight(){
      var bodyheight = window.innerheight;
      console.log({bodyheight})
      $('.nav-main').css({ 'width': bodyheight + 'px' });
    }
    
    // reset the height whenever the window's resized
    window.addEventListener("resize", resetHeight);
    
    // called to initially set the height.
    resetHeight();

});

您在 window 属性 上打错了字。

试试看 window.innerHeight