12345678910111213141516171819202122232425262728293031323334 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #can{
- background-color: #000;
- /* margin-left: 300px; */
- }
- </style>
- </head>
- <body>
- <canvas id="can" width="400" height="400"></canvas>
- <script>
- var can = document.querySelector('#can');
- var ctx = can.getContext('2d');
- ctx.strokeStyle = '#fff';
- ctx.lineWidth = 3;
- can.onmousedown = function(e){
- ctx.moveTo(e.offsetX,e.offsetY);
- can.onmousemove = function(e){
- ctx.lineTo(e.offsetX,e.offsetY);
- ctx.stroke();
- }
- }
- document.documentElement.onmouseup = function(){
- can.onmousemove = null;
- }
- </script>
- </body>
- </html>
|