[英]I've tried setting up my Canvas in JavaScript and it isn't working
I've restarted about 5 times and it's not working.我已经重新启动了大约 5 次,但没有用。 I'm trying to set up my canvas. The first part is the code in the js file and the second code is what I put in the HTML file.
我正在尝试设置我的 canvas。第一部分是 js 文件中的代码,第二部分是我放入 HTML 文件中的代码。
JS:记者:
var canvas;
var ctx;
var w = 1000;
var h = 600;
function setUpCanvas(){
canvas = document.querySelector("#myCanvas");
ctx = canvas.getContext("2d");
canvas.width = w;
canvas.height = h;
canvas.style.border = "5px dotted orange";
HTML: HTML:
<!DOCTYPE html>
<html>
<head>
<link rel ="stylesheet" type = "text/css" href = "m4.css">
</head>
<body>
<div id = "container">
<h1> module 4 : arrays and loops</h1>
<canvas id = "myCanvas"></canvas>
</div>
<script src = "m4.js"></script>
</body>
</html>
Simple answer, it works.简单的答案,它的工作原理。 for proof, visit
如需证明,请访问
https://loading.hermanboxcar5.repl.co https://loading.hermanboxcar5.repl.co
ok if you do ctrl u on that website it will give you the code you did (except my js file is named script.js
).好的,如果您在该网站上按 ctrl u,它会为您提供您所做的代码(除了我的 js 文件名为
script.js
)。 My best guess so far is after the last line of your js put a }
到目前为止,我最好的猜测是在你的 js 的最后一行之后放一个
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.