gpt4 book ai didi

javascript - 为什么在调整 Canvas 大小时出现滚动条?

转载 作者:行者123 更新时间:2023-11-30 10:44:26 28 4
gpt4 key购买 nike

我做了一个页面, Canvas 应该填满窗口。它有效,但由于某种原因出现滚动条。我不知道,错误是什么。

<!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>

最佳答案

将#canvas 切换为 block 对我有用:

#canvas {
display: block;
background-color: #EEEEEE;
}

关于javascript - 为什么在调整 Canvas 大小时出现滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9252608/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com