初探h5<canvas>标签

是h5的新标签,可以配合js画图.

<html>
<head>
<title>paintTest</title>
</head>
<script>
var p ; //全局变量,类似画笔

function init(){
p = document.getElementById('myCanvas').getContext('2d');

//矩形
p.strokeRect(100,50,200,300);//参数分别为左上角定点坐标,以及宽,高

//红色边框
p.lineWidth = 5 ; //线宽为5
p.strokeStyle = 'rgb(255,0,0)';//画笔颜色
p.strokeRect(400,50,100,100);

//蓝色矩形
p.fillStyle = 'rgb(0,0,255)';
p.fillRect(400,50,100,100);//填充矩形

//弧线(下半圆)
p.beginPath();
p.arc(200,50,100,0,Math.PI,false);
p.closePath();
p.stroke();

//弧线(上半圆  实心)
p.beginPath();
p.arc(500,500,100,0,Math.PI,true);
p.closePath();//闭合路径
p.fill(); //填充

//红色边框
p.strokeStyle = 'rgb(255,0,0)';
p.stroke();

}


</script>
<body onload="init()">
<canvas id="myCanvas" width="800" height="1000" >
your bowers don`t support h5 . (如果你的浏览器不支持h5则显示这一行!)
</canvas>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值