Jquery 确定浏览器高度&;宽度以将图像调整为全屏

Jquery 确定浏览器高度&;宽度以将图像调整为全屏,jquery,image,fullscreen,Jquery,Image,Fullscreen,我正在尝试使用jquery获取浏览器的高度和宽度,而不是使用这些信息来调整图像大小以适应该尺寸。我希望每页的图像都是全屏的,无论是在笔记本电脑上还是在大屏幕上观看。我现在所有的图像都是1280 dpi的标准宽度 为了查看到目前为止我已经将代码发布到我的纽约大学帐户:这完全可以通过CSS完成。我建议查看本教程: 下面的代码代表了超简单的CSS3方式。本教程还提供了其他备选方案 html { background: url(images/bg.jpg) no-repeat cent

我正在尝试使用jquery获取浏览器的高度和宽度,而不是使用这些信息来调整图像大小以适应该尺寸。我希望每页的图像都是全屏的,无论是在笔记本电脑上还是在大屏幕上观看。我现在所有的图像都是1280 dpi的标准宽度


为了查看到目前为止我已经将代码发布到我的纽约大学帐户:

这完全可以通过CSS完成。我建议查看本教程:

下面的代码代表了超简单的CSS3方式。本教程还提供了其他备选方案

html {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
}

这是我在过去使用过的,设置默认高度和宽度,然后尝试通过检索各种视口尺寸来计算它

var myWidth = 800;
var myHeight = 600;

    if ($.browser.msie) {
        if (typeof (window.innerWidth) == 'number') {

            myWidth = window.innerWidth;
            myHeight = window.innerHeight;

        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {

            //IE 6+ in 'standards compliant mode' 

            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;

        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {

            //IE 4 compatible 

            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;

        }
    }
    else {
        myWidth = $(window).width();
        myHeight = $(window).height();
    }
jQuery

关于调整大小

function imgsize() {
    var W = $(window).width(),
        H = $(window).height();

    $('img').height(H).width(W);
}
$(window).bind('resize', function() { imgsize(); });
CSS


好的,那很方便…你考虑过在这里发布你的代码吗,我们在哪里?顺便问一下,你不关心你的图像的纵横比吗?非常感谢!我唯一的问题是img的大小调整,因为我的图像是在一个数组中。我还希望它们保持高宽比。建议?这就是我的图像:$(function(){var images=['editorial/image1.jpg'、'editorial/image2.jpg'、'editorial/image3.jpg'、'editorial/image4.jpg'、'editorial/image5.jpg'、'editorial/image6.jpg'、'editorial/image7.jpg'、'editorial/image8.jpg';
function imgsize() {
    var W = $(window).width(),
        H = $(window).height();

    $('img').height(H).width(W);
}
$(window).bind('resize', function() { imgsize(); });
img {height: 100%; width: 100%;}