我做了一个页面,画布应该填满窗口。它可以工作,但由于某种原因出现了滚动条。我不知道,这是什么错误。
<!doctype html>
<html>
<head>
<title>test</title>
<meta charset="utf-8" />
<style type="text/css">
#canvas {
background-color: #EEEEEE;
}
* {
margin: 0px;
}
</style>
<script type="text/javascript">
function getSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
return {x:myWidth,y:myHeight};
}
window.onload = function () {
canvas = document.getElementById('canvas');
var size = getSize();
canvas.width = size.x;
canvas.height = size.y;
};
</script>
</head>
<body>
<canvas id="canvas" width="200" height="200"></canvas>
</body>
</html>