![](/img/trans.png)
[英]Why can't my javascript redirect the following code, I've tried multiple solution that i found in StackOverFlow
[英]I've tried setting up my Canvas in JavaScript and it isn't working
我已經重新啟動了大約 5 次,但沒有用。 我正在嘗試設置我的 canvas。第一部分是 js 文件中的代碼,第二部分是我放入 HTML 文件中的代碼。
記者:
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:
<!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>
簡單的答案,它的工作原理。 如需證明,請訪問
https://loading.hermanboxcar5.repl.co
好的,如果您在該網站上按 ctrl u,它會為您提供您所做的代碼(除了我的 js 文件名為script.js
)。 到目前為止,我最好的猜測是在你的 js 的最后一行之后放一個}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.