画布线不起作用IOS / IPAD

时间:2018-08-13 14:52:25

标签: javascript ios html5 canvas

嘿,我已经使用画布绘制了一个简单的点

    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上显示

1 个答案:

答案 0 :(得分:0)

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

我在末尾添加了适当的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>