代码
提交代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>慕课网Wiki</title> <style> #imooc{ border:1px solid #ccc; } </style> </head> <body> <canvas id="imooc"></canvas> <script> // 拿到一张白纸 const canvas = document.getElementById('imooc'); const ctx = canvas.getContext('2d'); // 打线笔移动到起点 ctx.moveTo(10,10); // 开始描线到终点 ctx.lineTo(100,50); // 选择绿色的画笔 ctx.strokeStyle="green"; // 开始用画笔描边 ctx.stroke(); </script> </body> </html>
运行结果