<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
>
<
title
>绘制径向渐变
</
title
>
<
script
>
function
draw(
id){
var
canvas=
document.
getElementById(
id);
if(
canvas==
null)
{
return
false;
}
var
context=
canvas.
getContext(
"2d");
//createRadiaGradient径向渐变
var
g1=
context.
createRadiaGradient(
400,
0,
0,
400,
0,
400);
g1.
addColorStop(
0.1,
"rgb(255,255,0)");
g1.
addColorStop(
0.3,
"rgb(255,0,255)");
g1.
addColorStop(
1,
"rgb(0,255,255)");
content.
fillStyle=
g1;
context.
fillRect(
0,
0,
500,
500);
context.
closePath();
context.
fill();
context.
stroken();
}
</
script
>
</
head
>
<
body
onload=
"draw("
canvas
");"
>
<
canvas
id=
"canvas"
width=
"500"
height=
"500"
></
canvas
>
</
body
>
</
html
>