fengchuanyu преди 1 седмица
родител
ревизия
2b9515a540
променени са 1 файла, в които са добавени 44 реда и са изтрити 0 реда
  1. 44 0
      6-HTML5/练习2_签字版.html

+ 44 - 0
6-HTML5/练习2_签字版.html

@@ -0,0 +1,44 @@
+<!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;
+        }
+    </style>
+</head>
+<body>
+    <canvas id="can" width="500" height="500"></canvas>
+    <script>
+        // 获取画布
+        var oCan = document.getElementById("can");
+        // 初始化画布
+        var oCtx = oCan.getContext("2d");
+
+        // 设置画笔样式
+        oCtx.lineWidth = 3;
+        oCtx.strokeStyle = '#fff';
+
+        // 绑定事件
+        oCan.onmousedown = function(e){
+            // 落笔
+            oCtx.moveTo(e.clientX,e.clientY);
+            // 移动事件
+            oCan.onmousemove = function(e){
+                // 移动画笔
+                oCtx.lineTo(e.clientX,e.clientY);
+                // 绘制
+                oCtx.stroke();
+            }
+        }
+        // 鼠标抬起
+        oCan.onmouseup = function(){
+            // 停止绘画
+            oCan.onmousemove = null;
+        }
+    </script>
+</body>
+</html>