首页 > 代码库 > canvas认识

canvas认识

1使用canvas绘制一个矩形

<canvas id="canvas" width="640" height="360"></canvas>

  

<script>//    获取context对象    var canvas = document.getElementById(‘canvas‘);    if(canvas.getContext) {        var context = canvas.getContext(‘2d‘);//        设置颜色        context.fillStyle = ‘rgb(255,0,0)‘;//        从坐标(20,30)开始,画一个64x36大小的矩形        context.fillRect(20,30,64,36);    }</script>

  

2

 

canvas认识