【问题标题】:Why does this canvas line have color in Chrome but not Firefox?为什么这条画布线在 Chrome 中有颜色,但在 Firefox 中没有?
【发布时间】:2014-10-27 18:42:29
【问题描述】:

http://jsfiddle.net/28z7mb9r/2/

var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(0, 0);
ctx.strokeStyle = "rgb(0, 0, 255);";
ctx.lineTo(100, 100);
ctx.stroke();

在 Chrome 中,小提琴显示为适当的蓝色。在 Firefox 中,它是黑色的。

【问题讨论】:

    标签: javascript html google-chrome firefox canvas


    【解决方案1】:

    事实证明,Firefox 对格式的要求更加严格,并且不允许在 strokeStyle 定义中使用分号。

    ctx.strokeStyle = "rgb(0, 0, 255)";
    

    以上在两种浏览器中都按预期工作。

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 2013-02-06
      • 1970-01-01
      • 2020-05-25
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2018-09-05
      相关资源
      最近更新 更多