温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Screen对象的使用方法

发布时间:2020-09-25 14:53:16 来源:亿速云 阅读:168 作者:小新 栏目:web开发

这篇文章给大家分享的是有关Screen对象的使用方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

Javascript的Screen对象可以获取有关用户显示的信息以及可用的颜色像素数,它可以用于获取有关客户端屏幕功能的信息,如宽度, 高度,颜色深度等,下面我们就来具体看看Screen对象的用法。

我们先来看一下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 ();">
    <h4>屏幕尺寸:</h4>
    Width: <span id="scrWidth"></span><br />
    Height: <span id="scrHeight"></span><br />
</body>

运行结果为:

Screen对象的使用方法

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

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 ();">
    <h4>可用面积尺寸:</h4>
    Width: <span id="availWidth"></span><br />
    Height: <span id="availHeight"></span><br />
</body>

运行结果为:

Screen对象的使用方法

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

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>

运行效果如下

Screen对象的使用方法

感谢各位的阅读!关于Screen对象的使用方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI