如何计算浏览器的主体宽度和高度

时间:2014-11-17 12:35:01

标签: html5 css3

如何在java查询中计算所有浏览器的主体宽度和高度...

$(document).ready(function () {
        $(document).ready(sizeContent01);
        function sizeContent01() {
            var totHeight = ($("body").height());
            var hdrHeight = $("#header").outerHeight(true);
            var ftrHeight = $("#footer").outerHeight(true);
            var bdyHeight1 = totHeight - hdrHeight - 10;
            var outputHeight = bdyHeight1 - $(".input_content").outerHeight(true) - 10;
            $("#body").css("height", bdyHeight1);
            $(".output_content").css("height", (outputHeight - 5));
        };
        $(window).resize(sizeContent02);
        function sizeContent02() {
            var totHeight = ($("body").height());
            var hdrHeight = $("#header").outerHeight(true);
            var ftrHeight = $("#footer").outerHeight(true);
            var bdyHeight1 = totHeight - hdrHeight - 10;
            var outputHeight = bdyHeight1 - $(".input_content").outerHeight(true) - 10;
            $("#body").css('height', bdyHeight1);
            $(".output_content").css('height', (outputHeight - 5));
        };
    });

请任何人帮助我......

2 个答案:

答案 0 :(得分:0)

在jQuery中:$( window ).height(); 在纯粹的js中:window.innerHeight;

至少我非常虔诚地对待这些。然后,如果你希望高度关闭整个html文档(包括滚动),你可以使用jQuery:$( document ).height();

答案 1 :(得分:0)

$(window).height();
$(window).width();

更多信息

如果您认为滚动条有问题,可以尝试隐藏它们然后进行测量

document.body.style.overflow = "hidden";
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
document.body.style.overflow = "";

重复Get the height and width of the browser viewport without scrollbars using jquery?

相关问题