Fill() | HTML<canvas>方法
定义与用法
fill() 方法填充当前的图像(路径)。默认颜色是黑色。
提示:请使用 fillStyle 属性来填充另一种颜色/渐变。
提示:如果路径未关闭,那么 fill() 方法会从路径结束点到开始点之间添加一条线,以关闭该路径(正如 closePath() 一样),然后填充该路径。
语法格式
context.fill();
示例代码
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.rect(20, 20, 150, 100);
ctx.fillStyle = "red";
ctx.fill();
</script>
效果展示:
浏览器支持
方法 | |||||
---|---|---|---|---|---|
Fill() | Yes | Yes | Yes | Yes | Yes |
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 fill() 方法。
提示:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。