App下載
首頁(yè)javascriptdrawing_settingsCanvas - 如何從上下文引用canvas

Canvas - 如何從上下文引用canvas

我們想知道如何從上下文引用canvas。





<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>//<![CDATA[ 
function lineDraw() {   
    var canvas=document.getElementById("myCanvas");
    var context=canvas.getContext("2d");
    context.canvas.width = context.canvas.width;
    context.moveTo(0,0);
    context.lineTo(event.clientX,event.clientY);
    context.stroke();
}
//]]>  
</script>
</head>
<body onmousemove="lineDraw()">
   <canvas id="myCanvas" width="640" height="480"/>
</body>
</html>