2014-05-19 23 views
0

工作,我有以下代码:与阵列帆布setLineDash不会在Firefox,但在Chrome

[ 
    { 
     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); 
} 

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

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

回答

0

知道,我知道故障:[0,0]没有形成一条线(0行,0之间的空格!)。我必须将第一个值设置为大于0的任何数字,并让其他0。然后,这是一条实线。

相关问题