欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您也可以使用fillStyle()方法在画布形状中填充颜色。
 
以下示例将向您展示如何在矩形形状内填充纯色。
 
例试试这个代码»
<script>
window.onload = function() {
        var canvas = document.getElementById("myCanvas");
        var context = canvas.getContext("2d");
        context.rect(50, 50, 200, 100); 
        context.fillStyle = "#FB8B89";
        context.fill();
        context.lineWidth = 5;
        context.strokeStyle = "black";
        context.stroke();
    };
</script>
提示:在画布上设置形状的样式时,建议在fill()方法之前使用stroke()方法,以正确渲染笔触。
 
同样,您也可以使用该fillStyle()方法在圆内填充纯色。
 
例试试这个代码»
<script>
window.onload = function() {
        var canvas = document.getElementById("myCanvas");
        var context = canvas.getContext("2d");
        context.arc(150, 100, 70, 0, 2 * Math.PI, false);
        context.fillStyle = "#FB8B89";
        context.fill();
        context.lineWidth = 5;
        context.strokeStyle = "black";
        context.stroke();
    };
</script>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h60950.shtml