练习1_画板.html 870 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: black;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <canvas id="can" width="500" height="400"></canvas>
  15. <script>
  16. var oCan = document.getElementById("can");
  17. var aCan = oCan.getContext("2d");
  18. aCan.strokeStyle = "white";
  19. aCan.lineWidth = 3;
  20. oCan.onmousedown = function(event){
  21. aCan.moveTo(event.clientX,event.clientY);
  22. oCan.onmousemove = function(event){
  23. aCan.lineTo(event.clientX,event.clientY);
  24. aCan.stroke();
  25. }
  26. }
  27. oCan.onmouseup = function(){
  28. oCan.onmousemove = null;
  29. }
  30. </script>
  31. </body>
  32. </html>