找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 js教程 查看内容

JavaScript中innerWidth和innerHeight属性详解

作者:模板之家 2019-3-27 14:51 130人关注

JavaScript中的innerWidth属性返回宽度,innerHeight属性返回窗口内容区域的高度。 语法: window.innerWidth window.innerHeight

JavaScript中的innerWidth属性返回宽度,innerHeight属性返回窗口内容区域的高度。

语法:

window.innerWidth
window.innerHeight

参数:它不需要任何参数。

返回值:返回一个数字,表示窗口内容区域的宽度和高度。

注意:对于IE 8 ie(Internet Edg 8)或更早版本,请使用clientWidth和clientHeight获取窗口的宽度和高度。

示例:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>浏览器内部的宽度和高度</title>
    <style>
        body{
            text-align:center;
        }
        .gfg {
            font-size:40px;
            font-weight:bold;
            color:green;
        }
    </style>
</head>
<body>
<div class = "gfg">PHP中文网</div>
<h2>浏览器窗口</h2>
<p id="demo"></p>
<script>
    var Width, Height, result;

    // 浏览器窗口的高度和宽度
    Width = window.innerWidth || document.documentElement.clientWidth
        || document.body.clientWidth;

    Height = window.innerHeight || document.documentElement.clientHeight
        || document.body.clientHeight;
    // 显示宽度和高度。
    result = document.getElementById("demo");
    result.innerHTML = "浏览器内部宽度: " + Width +
        "<br>浏览器内部高度: " + Height;

</script>
</body>
</html>

输出:

09954caece181f0b7f7322afc6258ab.png

相关推荐:《javascript教程》

本篇文章就是关于JavaScript中Window innerWidth和innerHeight属性的相关介绍,希望对需要的朋友有所帮助!

以上就是JavaScript中innerWidth和innerHeight属性详解的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: [db:来源]

全部回复(0)

发表评论