功能描述
大小自适应屏幕,效果见下图
知识摘记
屏幕对象 screen
- 屏幕对象主要包含了计算机屏幕的尺寸及颜色信息
- 这些信息只能读取,不可以设置
- 属性:
- height 返回显示器屏的高度
- width 返回显示器屏的宽度
- availHeight 返回显示器屏的宽度,除Windows任务栏之外
- availWidth 返回显示器屏的宽度,除Windows任务栏之外
元素.style.width = screen.availWidth*比例+"px";
代码展示
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#out {
/*width: 80%;*/
height: 200px;
background-color: red;
margin: 10px auto;
padding: 10px;
}
.left {
width: 500px;
height: 100px;
background-color: green;
float: left;
}
.right {
width: 500px;
height: 100px;
background-color: yellow;
float: right;
}
</style>
<script type="text/javascript">
window.onload = function(){
var out = document.getElementById('out');
out.style.width = screen.availWidth*0.8+"px";
}
</script>
</head>
<body>
<div id="out">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>