HTML5 canvas beginPath() 方法
實(shí)例
在畫布上繪制兩條路徑;紅色和藍(lán)色:
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d");ctx.beginPath();
ctx.lineWidth="5"; ctx.strokeStyle="red"; // 紅色路徑 ctx.moveTo(0,75); ctx.lineTo(250,75); ctx.stroke(); // 進(jìn)行繪制ctx.beginPath();
ctx.strokeStyle="blue"; // 藍(lán)色路徑 ctx.moveTo(50,0); ctx.lineTo(150,130); ctx.stroke(); // 進(jìn)行繪制
瀏覽器支持
Internet Explorer 9、Firefox、Opera、Chrome 以及 Safari 支持 beginPath() 方法。
注釋:Internet Explorer 8 或更早的瀏覽器不支持 <canvas> 元素。
定義和用法
beginPath() 方法開始一條路徑,或重置當(dāng)前的路徑。
提示:請(qǐng)使用這些方法來創(chuàng)建路徑:moveTo()、lineTo()、quadricCurveTo()、bezierCurveTo()、arcTo() 以及 arc()。
提示:請(qǐng)使用 stroke() 方法在畫布上繪制確切的路徑。
JavaScript 語法:
context.fillRect(x,y,width,height);