I am trying to embed the p5.js output canvas into my webpage by following this tutorial. I hope the canvas will display where I placed it inside the HTML body. However, it will always be at the very bottom of my page. I tried to play around with CSS, especially position
and display
, but nothing special other than display: none;
... The same thing happened when I tried to place the script inside the body. Moreover, the canvases will overlap if multiple scripts are included.
Here are some example codes:
index.html
<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/p5@1.5.0/lib/p5.min.js"></script>
<script src="test.js"></script>
</head>
<body>
<h1>Hello World</h1>
<p>This is a sentence</p>
</body>
</html>
test.js
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
circle(200,200,50,50);
}