Reputation: 11
why color not appear by this code
function doFirst(){
var x= document.getElementById('canvas');
canvas=x.getContext('2d');
var g=canvas.createLinearGradient(0,0,100,100);
g.addColorStop(.0,"blue");
g.addColorStop(1,"red");
canvas.fillstyle=g;
canvas.fillRect(0,0,100,100);
}
window.addEventListener("load", doFirst, false);
Upvotes: 1
Views: 73
Reputation: 11
it worked. now why this is not working: `function doFirst(){ var x = document.getElementById('canvas'); canvas = x.getContext('2d');
canvas.shadowOffsetX = 4;
canvas.shadowOffsetY = 4;
canvas.shadowBlur = 6;
canvas.shadowColor='rgba(0,0,255,.5)';
canvas.font="bold 3px Tahoma";
canvas.textAlign="end";
canvas.fillText("ongwtfbbq",300,100);
} window.addEventListener("load", doFirst, false);`
Upvotes: 0
Reputation: 4154
You have a typo in your code, there should be canvas.fillStyle
instead of canvas.fillstyle
.
function doFirst(){
var x = document.getElementById('canvas');
canvas = x.getContext('2d');
var g = canvas.createLinearGradient(0,0,100,100);
g.addColorStop(.0,"blue");
g.addColorStop(1,"red");
canvas.fillStyle = g;
canvas.fillRect(0,0,100,100);
}
window.addEventListener("load", doFirst, false);
<canvas id="canvas"></canvas>
Hope this helps!
Upvotes: 1