日期:2014-05-17 浏览次数:20697 次
var c=this.callout[0]; var cxt=c.getContext("2d"); cxt.beginPath(); cxt.moveTo(x0,y0); cxt.lineTo(x1,y1); cxt.lineTo(x2,y2); cxt.lineTo(x3,y3); cxt.lineTo(x4,y4); cxt.closePath(); cxt.fillStyle="#000000"; cxt.fillText("hello world", x,y); cxt.fill(); cxt.stroke();
<!DOCTYPE html> <html> <head> <title>Canvas beginePath example</title> <script> function beginDemo() { var canvas = document.getElementById("demo") var ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.lineWidth = "3"; ctx.strokeStyle = "blue"; ctx.fillStyle = "orange"; ctx.moveTo(100, 100); ctx.lineTo(100, 400); ctx.lineTo(400, 400); ctx.lineTo(400, 100); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.font = "32pt Arial"; ctx.strokeText("我是中文字", 120, 200); ctx.strokeStyle = "red"; ctx.stroke(); } </script> </head> <body onload="beginDemo();"> <canvas id="demo" width="800" height="800"></canvas> </body> </html>