canvas智能语法提示,初学canvas时没有语法提示,我们可以通过加入`/** @type {HTMLCanvasElement} */`代码使canvas智能提示。

canvas语法提示:

初学canvas时没有语法提示,我们可以通过加入
/** @type {HTMLCanvasElement} */
代码使canvas智能提示,
例如:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="cvs" width="500px" height="500px"></canvas>
    <script>
        /** @type {HTMLCanvasElement} */
        let c1 = document.querySelector('#cvs')
        let ctx = c1.getContext('2d');
        ctx.fillRect(100, 100, 100, 100)
    </script>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_51602285/article/details/127991322