代码描述:screen.width和screen.height属性作用。screen.width和screen.height属性作用源码下载
本章节通过代码实例介绍一下标题中两个属性的用法,希望能够给需要的朋友带来帮助。 两个属性可以反别返回显示器的宽度和高度,以像素计。 在标准浏览器中,这两个属性返回的是设备像素。 代码实例:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> *{ margin:0px; padding:0px; text-align:center; } #antzone{ width:200px; height:100px; background:#CCC; display:none; text-align:center; } </style> <script type="text/javascript"> window.onload=function(){ var odiv=document.getElementById("antzone"); var obt=document.getElementById("bt"); obt.onclick=function(){ odiv.style.display="block"; odiv.style.position="absolute"; odiv.style.left=(screen.width-200)/2+"px"; odiv.style.top=(screen.height-100)/2+"px"; } } </script> </head> <body> <div id="antzone">softwhy.com</div> <input type="button" id="bt" value="查看效果"/> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能