10
0

练习题1_画板.html 851 B

123456789101112131415161718192021222324252627282930313233
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. #can{
  9. background-color: #000;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <canvas id="can" width="400" height="300"></canvas>
  15. <script>
  16. var oCan = document.getElementById("can");
  17. var can = oCan.getContext("2d");
  18. can.strokeStyle = "white";
  19. can.lineWidth = 3;
  20. oCan.onmousedown = function(e){
  21. can.moveTo(e.clientX,e.clientY);
  22. oCan.onmousemove = function(e){
  23. can.lineTo(e.clientX,e.clientY);
  24. can.stroke();
  25. }
  26. oCan.onmouseup = function(){
  27. oCan.onmousemove = null;
  28. }
  29. }
  30. </script>
  31. </body>
  32. </html>