简单教程
提交运行
代码编辑器:
<p>图片应用:</p> <img id="scream" src="/static/i/img3.jpg" width="400"> <p>画布:</p> <canvas id="canvas-3" width="300" height="150" style="border:1px solid #d3d3d3;background:#ffffff;">你的浏览器不支持 canvas 元素</canvas> <script> var img3 = document.createElement("img"); img3.src="/static/i/img3.jpg"; img3.onload= function() { var c=document.getElementById("canvas-3"); var canvOK=1; try {c.getContext("2d");} catch (er) {canvOK=0;} if (canvOK==1) { var ctx=c.getContext("2d"); var img= this; ctx.drawImage(img,90,130,50,60,10,10,50,60); } } </script>
运行结果: