1. Because canvas canvas in a Web page, you need to add a canvas tag in html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <!-- 创建一个宽300px, 高300px的画布环境 --> <canvas id="c1" width="300" height="300"></canvas> </body> </html>
2. We need to control the canvas, draw graphics inside the canvas, then you need to control js:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id="c1" width="300" height="300"></canvas> <script> var canvas = document.getElementById("c1"); var ctx = canvas.getContext("2d"); ctx instanceof CanvasRenderingContext2D; // true </script> </body> </html>
After completion of the two steps above can be considered initially a canvas (canvas) environment.