【发布时间】:2013-12-09 14:43:58
【问题描述】:
我使用以下代码将样式设置为“画布”。但我无法将"fillStyle" 设置为画布。但是strokeStyle 和lineWidth 工作正常。
Init(){
var can = byId('myCanvas');
// get it's context
hdc = can.getContext('2d');
hdc.strokeStyle = 'red';
hdc.lineWidth = 2;
// Fill the path
hdc.fillStyle = "#9ea7b8";
hdc.fill();
}
//并用坐标调用drawPoly函数。
function drawPoly(coOrdStr) {
var canvas = byId('myCanvas');
hdc.clearRect(0, 0, canvas.width, canvas.height);
var mCoords = coOrdStr.split(',');
var i, n;
n = mCoords.length;
hdc.beginPath();
hdc.moveTo(mCoords[0], mCoords[1]);
for (i = 2; i < n; i += 2) {
hdc.lineTo(mCoords[i], mCoords[i + 1]);
}
hdc.lineTo(mCoords[0], mCoords[1]);
hdc.stroke();
}
有人可以帮忙吗?
【问题讨论】:
-
我多次更改了 fillStyle 颜色。但没有变化。
-
您需要指定要填充的内容...一个矩形、一个圆形...您关闭了笔触路径?
-
你还没有画任何东西。
-
我已经删除了所有提到 jQuery 的内容,因为这个问题与它无关。没有可用于画布的 jQuery 方法。
标签: javascript html canvas excanvas