Javascript jQuery widthRatio在IE8上返回NaN

Javascript jQuery widthRatio在IE8上返回NaN,javascript,jquery,internet-explorer-8,Javascript,Jquery,Internet Explorer 8,我有全屏网站。当我点击我的页面时,图像直接调整全屏大小。它正在开发IE9-10、Chrome和Firefox。但不要在IE8上工作 我的JS代码: $(window).resize(function () { $("#backgrounds img").each(function (k, v) { $backgroundImg = $(this); windowWidth = window.innerWidth windowHeight

我有全屏网站。当我点击我的页面时,图像直接调整全屏大小。它正在开发IE9-10、Chrome和Firefox。但不要在IE8上工作

我的JS代码:

$(window).resize(function () { 
    $("#backgrounds img").each(function (k, v) {
        $backgroundImg = $(this);

        windowWidth = window.innerWidth
        windowHeight = window.innerHeight
        imageWidth = 1366
        imageHeight = 900

        widthRatio = windowWidth / imageWidth;
        heightRatio = windowHeight / imageHeight;

        console.log('width: ' + widthRatio)
        console.log('height: ' + heightRatio)

        if (widthRatio > heightRatio) {
            $backgroundImg.width(windowWidth);
            $backgroundImg.height(imageHeight * widthRatio);
        } else {
            $backgroundImg.height(windowHeight);
            $backgroundImg.width(imageWidth * heightRatio);
        }
        $backgroundImg.css({ marginLeft: -$backgroundImg.width() / 2 });
        $backgroundImg.css({ left: "50%" });
    });

});     
当我检查例如Chrome上的控制台时,获取以下数据:

width: 1.3711566617862372 
height: 0.7488888888888889 
但当我在IE8上检查此函数时,得到以下结果:

height: NaN 
 width: NaN

已在StackoverFlow上搜索,但未找到解决方案。我怎样才能修好它?谢谢。

内部宽度不受IE8支持

所有的支持都使用这个

var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;

是的,这是innerWidth支持问题,通过以下链接解决:

因此,在我的js文件中添加了此函数:

(function (window, html, body) {
    if (!window.innerWidth) Object.defineProperty(window, 'innerWidth', {
        get: function () { return html.clientWidth }
    });

    if (!window.innerHeight) Object.defineProperty(window, 'innerHeight', {
        get: function () { return html.clientHeight }
    });


}(this, document.documentElement, document.body));
谢谢大家!