百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>JS教程> Screen对象如何使用
分享文章到:

Screen对象如何使用

发布时间:09/01 来源:未知 浏览: 关键词:
Javascript的Screen对象可以猎取有关会员显示的信息乃至可用的色彩像素数,它可以用于猎取有关客户端屏幕功效的信息,如宽度, 高度,色彩深度等,下面我们就来详细看看Screen对象的用途。

JavaScript

我们先来看一下Screen对象的属性

screen.width:返回屏幕的宽度。

screen.height:返回屏幕的高度。

screen.availWidth:返回可用的宽度。

screen.availHeight:返回可用高度。

screen.colorDepth:返回色彩深度。

screen.pixelDepth:返回像素深度。

接下来我们来看这些属性的详细利用

先来看一下屏幕宽高

screen.width属性返回会员屏幕宽度(以像素为单位)。

screen.height属性返回会员屏幕高度(以像素为单位)。

详细示例如下

<head>
    <script type="text/javascript">
        function GetDimensions () {
            var scrWidth = document.getElementById ("scrWidth");
            scrWidth.innerHTML = screen.width;
            var scrHeight = document.getElementById ("scrHeight");
            scrHeight.innerHTML = screen.height;
        }
    </script>
</head>
<body onload="GetDimensions ();">
    <h3>屏幕尺寸:</h3>
    Width: <span id="scrWidth"></span><br />
    Height: <span id="scrHeight"></span><br />
</body>

运转结果为:

微信截图_20190129155653.png

接着我们来看一下屏幕可用宽高

screen.availWidth属性返回会员屏幕宽度(以像素为单位),不包罗界面功效。

screen.availHeight属性返回会员屏幕高度(以像素为单位),不包罗界面功效。

示例如下:

<head>
    <script type="text/javascript">
        function GetDimensions () {
            var availWidth = document.getElementById ("availWidth");
            availWidth.innerHTML = screen.availWidth;
            var availHeight = document.getElementById ("availHeight");
            availHeight.innerHTML = screen.availHeight;
        }
    </script>
</head>
<body onload="GetDimensions ();">
    <h3>可用面积尺寸:</h3>
    Width: <span id="availWidth"></span><br />
    Height: <span id="availHeight"></span><br />
</body>

运转结果为:

微信截图_20190129160122.png

最后我们来看一下屏幕色彩和像素数

screen.colorDepth属性返回用于显示一种色彩的位(数字)。

screen.pixelDepth属性返回屏幕的像素深度

示例如下

<head>
    <script type="text/javascript">
        function GetDimensions () {
             var colorDepth =document.getElementById("colorDepth");
            colorDepth.innerHTML = screen.colorDepth; 
            var pixelDepth =document.getElementById("pixelDepth");
            pixelDepth.innerHTML =  screen.pixelDepth; 
        }
    </script>
</head>
<body onload="GetDimensions ();">
   color:<span id="colorDepth"></span><br />
    pixel:<span id="pixelDepth"></span>
</body>

运转结果如下

微信截图_20190129160349.png

本篇文章到这里就全部完毕了,更多出色内容大家可以关注百分百源码网的其他相关栏目教程!!!

以上就是Screen对象如何使用的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有151人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板