gpt4 book ai didi

javascript - html Canvas 没有填充颜色

转载 作者:太空宇宙 更新时间:2023-11-04 14:56:00 28 4
gpt4 key购买 nike

我一直在学习如何制作简单 Canvas 的教程。但是,即使我完全按照教程进行操作, Canvas 也没有显示任何颜色。任何帮助。它困扰着我:/

<html>

some text here

<canvas id="gamecanvas" width="800" height="600></canvas>]

<script>
var Canvas;
var canvasContext;

window.onload = function() {
console.log("Hello world!");
Canvas = document.getElementById("gamecanvas");
canvasContext = canvas.getcontext('2d');
canvasContext.fillStyle = 'red';
canvasContext.fillRect(0,0,canvas.width,canvas.height);
}
</script>
</html>

编辑:感谢您的帮助。解决了!

最佳答案

语法错误太多。

这是有效的

<html>

some text here

<canvas id="gamecanvas" width="800" height="600"></canvas>

<script>
var Canvas;
var canvasContext;

window.onload = function() {
console.log("Hello world!");
Canvas = document.getElementById("gamecanvas");
canvasContext = Canvas.getContext('2d');
canvasContext.fillStyle = 'red';
canvasContext.fillRect(0,0,Canvas.width,Canvas.height);

}
</script>
</html>

关于javascript - html Canvas 没有填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42392591/

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