最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

HTML5 canvas createLinearGradient() 方法

實(shí)例

定義從黑到白的漸變(從左向右),作為矩形的填充樣式:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

var grd=ctx.createLinearGradient(0,0,170,0);
grd.addColorStop(0,"black");
grd.addColorStop(1,"white");

ctx.fillStyle=grd;
ctx.fillRect(20,20,150,100);

親自試一試

瀏覽器支持

Internet Explorer 9、Firefox、Opera、Chrome 以及 Safari 支持 createLinearGradient() 方法。

注釋:Internet Explorer 8 或更早的瀏覽器不支持 <canvas> 元素。

定義和用法

createLinearGradient() 方法創(chuàng)建線性的漸變對象。

漸變可用于填充矩形、圓形、線條、文本等等。

提示:請使用該對象作為 strokeStylefillStyle 屬性的值。

提示:請使用 addColorStop() 方法規(guī)定不同的顏色,以及在 gradient 對象中的何處定位顏色。

JavaScript 語法:

context.createLinearGradient(x0,y0,x1,y1);

參數(shù)值

參數(shù) 描述
x0 漸變開始點(diǎn)的 x 坐標(biāo)
y0 漸變開始點(diǎn)的 y 坐標(biāo)
x1 漸變結(jié)束點(diǎn)的 x 坐標(biāo)
y1 漸變結(jié)束點(diǎn)的 y 坐標(biāo)

更多實(shí)例

實(shí)例 1

定義一個(gè)漸變(從上到下)作為矩形的填充樣式:

Your browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var my_gradient=ctx.createLinearGradient(0,0,0,170);
my_gradient.addColorStop(0,"black");
my_gradient.addColorStop(1,"white");
ctx.fillStyle=my_gradient;
ctx.fillRect(20,20,150,100);

親自試一試

實(shí)例 2

定義一個(gè)從黑到紅再到白的漸變,作為矩形的填充樣式:

Your browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var my_gradient=ctx.createLinearGradient(0,0,170,0);
my_gradient.addColorStop(0,"black");
my_gradient.addColorStop(0.5,"red");
my_gradient.addColorStop(1,"white");
ctx.fillStyle=my_gradient;
ctx.fillRect(20,20,150,100);

親自試一試

霍城县| 黄龙县| 长海县| 奎屯市| 定西市| 泰宁县| 兴宁市| 泽州县| 新巴尔虎左旗| 宜城市| 德格县| 安岳县| 惠东县| 化隆| 靖边县| 曲麻莱县| 沽源县| 浦县| 水富县| 揭西县| 洛南县| 武义县| 清河县| 珲春市| 清涧县| 雷州市| 九龙城区| 河源市| 阿荣旗| 辽宁省| 迭部县| 江华| 沽源县| 修水县| 广安市| 竹山县| 元氏县| 五常市| 逊克县| 忻州市| 图们市|