日期:2014-05-17  浏览次数:20726 次

html5 canvas例子
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>HTML5</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<script type="text/javascript">
$(document).ready(function(){
	var canvas = $("#canvas").get(0);
	var ctx = canvas.getContext("2d");
	
	var width = canvas.width;
	var height = canvas.height;
	
	ctx.beginPath();
	ctx.moveTo(0,0);
	ctx.lineTo(width,0);
	ctx.lineTo(width, height);
	ctx.lineTo(0, height);
	ctx.lineTo(0, 0);
	ctx.lineWidth=12;
	ctx.lineCap="round";
	ctx.stroke();
	
	
	$("#canvas").click(function(event) {
		ctx.moveTo(event.pageX,event.pageY);
		ctx.lineTo(0,0);
		ctx.stroke();
	});
});
</script>
</body>
</html>