canvas setLineDash with array不能在Firefox中工作,但在Chrome中

canvas setLineDash with array doesn't work in Firefox but in Chrome

本文关键字:工作 但在 Chrome Firefox setLineDash with array 不能 canvas      更新时间:2023-09-26

我有以下代码:

[
    {
      lineDash: [0, 0],
      strokeStyle: '#909090',
      lineWidth: lineWidth,
    },
    {
      lineDash: [0, 0],
      strokeStyle: '#e5e5e5',
      lineWidth: lineWidth -10,
    },
    {
      lineDash: [0, 0],
      strokeStyle: '#909090',
      lineWidth: lineWidth -26,
    },
    {
      lineDash: [20, 14],
      strokeStyle: '#ffffff',
      lineWidth: 3,
    },
  ].forEach(function(entry) {
    ctx.beginPath();
    ctx.lineWidth = entry.lineWidth;
    ctx.strokeStyle = entry.strokeStyle;
    ctx.setLineDash(entry.lineDash);
}

设置lineWidth和strokeStyle工作得很好,但setLineWidth在Firefox中没有,我在控制台没有得到错误。在Chrome中,它可以工作。如果我不说'ctx.setLineDash(entry. linedash);' 'ctx.setLineDash(entry. linedash);lineDash[0], entry.lineDash[1]);', Firefox控制台显示'TypeError: CanvasRenderingContext2D的参数1。setLineDash不能转换为序列。'和Chrome控制台意味着'Uncaught TypeError:第一个参数既不是数组,也没有索引属性'。

你知道如何解决这个问题吗?提前感谢!

知道了,我知道这个错误:[0,0]不成行(0行,0空格!?)我必须将第一个值设为大于0的任意数另一个设为0。然后是实线

相关文章: