Sid*_*bhu -3 html javascript canvas
lineTo()功能对我不起作用,为什么?这是代码。
<canvas id="sid" height="1000px" width="1000px"> </canvas>
<script>
var can = document.querySelector('#sid');
var a = can.getContext('2d');
a.beginPath();
a.moveTo(0, 0);
a.lineTo(140, 140);
a.lineTo(160, 160);
</script>
Run Code Online (Sandbox Code Playgroud)
您忘记调用该stroke()函数。查看文档对您非常有帮助,其中以更清晰的方式进行了解释。
来自文档:
Canvas 2D API 的方法
CanvasRenderingContext2D.stroke()使用非零缠绕规则以当前笔划样式对当前或给定路径进行笔划。
<canvas id="sid" height="1000px" width="1000px"></canvas>
<script>
var can = document.querySelector('#sid');
var a = can.getContext('2d');
a.beginPath();
a.moveTo(0, 0);
a.lineTo(140, 140);
a.lineTo(160, 160);
// After this you need to run the stroke command to get the line.
a.stroke();
</script>Run Code Online (Sandbox Code Playgroud)