js之screen对象

来源:互联网 发布:智能推荐算法有哪些 编辑:程序博客网 时间:2024/05/22 13:17

screen对象

screen对象用于获取用户的屏幕信息。

语法:

window.screen.属性

对象属性:

屏幕分辨率的高和宽

window.screen 对象包含有关用户屏幕的信息。
1. screen.height 返回屏幕分辨率的高
2. screen.width 返回屏幕分辨率的宽
注意:
1.单位以像素计。
2. window.screen 对象在编写时可以不使用 window 这个前缀。
我们来获取屏幕的高和宽,代码如下:

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>屏幕分辨率的高和宽</title></head><body><script type="text/javascript">document.write( "屏幕宽度:" + window.screen.width + "px<br/>" );document.write( "屏幕高度:" + window.screen.height + "px");       </script></body></html>

运行结果:
屏幕宽度:1600px屏幕高度:900px 

屏幕可用高和宽度

1. screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去界面特性,比如任务栏。

2. screen.availHeight 属性返回访问者屏幕的高度,以像素计,减去界面特性,比如任务栏。

注意:

不同系统的任务栏默认高度不一样,及任务栏的位置可在屏幕上下左右任何位置,所以有可能可用宽度和高度不一样。

我们来获取屏幕的可用高和宽度,代码如下:

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>屏幕分辨率的高和宽</title></head><body><script type="text/javascript">document.write("可用宽度:" + window.screen.availWidth + "px<br/>");document.write("可用高度:" + window.screen.availHeight +"px");     </script></body></html>


0 0
原创粉丝点击