首页 > 解决方案 > Canvas LineTo 不工作 IOS / IPAD

问题描述

嘿,我用画布画了一个简单的点

    ctx.lineWidth = 5;
    ctx.lineJoin = 'round';
    ctx.lineCap = 'round';
    ctx.strokeStyle = 'blue';
 ctx.beginPath();
        //ctx.moveTo(last_mouse.x, last_mouse.y);
ctx.lineTo(120, 40);

但它在 IOS 上不显示点仅在 Android / Windows 上显示

标签: javascriptioshtmlcanvas

解决方案


您的代码在任何浏览器上都没有为我绘制任何东西......

我在最后添加了一个适当的 moveTo 和一个中风,这是示例:

<canvas id="canvas" style="border:1px solid #000000;"></canvas>
<script>
  var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  ctx.lineJoin = ctx.lineCap = 'round';

  // Draw a Blue dot on the middle of the canvas
  ctx.beginPath();
  ctx.lineWidth = 50;
  ctx.strokeStyle = 'blue';
  ctx.lineTo(canvas.width / 2, canvas.height / 2);
  ctx.stroke();

  // Draw a diagonal Red line on the canvas
  ctx.beginPath();
  ctx.lineWidth = 5;
  ctx.strokeStyle = 'red';
  ctx.moveTo(20, 20);
  ctx.lineTo(canvas.width - 20, canvas.height - 20);
  ctx.stroke();
</script>


推荐阅读