1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > fillstyle属性_html设置或返回用于填充绘画的颜色渐变或模式的属性fillStyle

fillstyle属性_html设置或返回用于填充绘画的颜色渐变或模式的属性fillStyle

时间:2019-05-27 01:01:31

相关推荐

fillstyle属性_html设置或返回用于填充绘画的颜色渐变或模式的属性fillStyle

实例

定义用蓝色填充的矩形:

JavaScript:var c=document.getElementById("myCanvas");

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

ctx.fillStyle="#0000ff";

ctx.fillRect(20,20,150,100);

浏览器支持

Internet Explorer 9、Firefox、Opera、Chrome 以及 Safari 支持 fillStyle 属性。

注释:Internet Explorer 8 以及更早的版本不支持 元素。

定义和用法

fillStyle 属性设置或返回用于填充绘画的颜色、渐变或模式。默认值:#000000

JavaScript 语法:context.fillStyle=color|gradient|pattern;

属性值值描述

color指示绘图填充色的 CSS 颜色值。默认值是 #000000

gradient用于填充绘图的渐变对象(线性或放射性)

pattern用于填充绘图的 pattern 对象

更多实例

实例 1

定义从上到下的渐变,作为矩形的填充样式:

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);

实例 2

定义从左到右的渐变,作为矩形的填充样式:

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(1,"white");

ctx.fillStyle=my_gradient;

ctx.fillRect(20,20,150,100);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。