具体像这样~~ case 13: //给出两个点的x和y坐标,就可以在这两个点之间画一条直线 break;
谢谢!
<canvas width="240" height="320"> <text id="rt" text="hello"/> <drawview id="draw2"> <handler name="oninit"> <![CDATA[ this.clear(); this.rect(172, 55, 65, 31); this.strokeStyle = red; this.stroke(); ]]> </handler> </drawview> <handler name="onkeydown" reference="LzKeys" args="key"> <![CDATA[ draw2.moveTo(0, 0); draw2.lineTo(100, 100); draw2.stroke(); ]]> </handler> <handler name="oninit"> LzFocus.setFocus(canvas); </handler> </canvas>
上例中演示了如何动态画直线,用moveTo方法移动到直线起始点,用lineTo方法画到直线终止点,调用stroke方法画线。若要清除之前画的线条,在方法最开始调用clear方法清除。