chiark / gitweb /
wip non dnd, wip refactor for movement
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jun 2020 20:52:06 +0000 (21:52 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jun 2020 20:52:06 +0000 (21:52 +0100)
templates/script.js
templates/test.html

index 8203606506f26834b034d1024486277256f48944..607c883407fa4ce49fc212a495ff3a19be9eaab7 100644 (file)
@@ -17,8 +17,8 @@ function drag_mousedown(e) {
   dcx = e.clientX;
   dcy = e.clientY;
   delt = e.target;
-  dox = parseFloat(delt.getAttributeNS(null,"cx"));
-  doy = parseFloat(delt.getAttributeNS(null,"cy"));
+  dox = parseFloat(delt.getAttributeNS(null,"x"));
+  doy = parseFloat(delt.getAttributeNS(null,"y"));
   dragging = false;
   window.addEventListener('mousemove', drag_mousemove, true);
   window.addEventListener('mouseup',   drag_mouseup,   true);
@@ -39,8 +39,8 @@ function drag_mousemove(e) {
   if (dragging) {
     var x = dox + ddx;
     var y = doy + ddy;
-    delt.setAttributeNS(null, "cx", x);
-    delt.setAttributeNS(null, "cy", y);
+    delt.setAttributeNS(null, "x", x);
+    delt.setAttributeNS(null, "y", y);
     console.log(delt);
   }
 }
index 923d38a9b061f57bfb39228f9f13e670ea9e5a66..c16a284f94afb17083cd4fb828cf77d33af05411 100644 (file)
@@ -2,19 +2,24 @@
     <title>T</title>
   </head>
   <body>
-<div id="status">nothing</div>
-<p>
-  <svg id="space"
-       xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 200"
-       ondragstart="test_dragstart(event)"
-       >
+    <p>
+      <div id="status">nothing</div>
+    </p>
+    <svg id="space"
+        xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 200"
+        >
       <rect fill="green" x="42" y="56" width="100" height="80"/>
-      <circle
-       draggable="true"
-       onmousedown="drag_mousedown(event)"
-       data-objid="42"
-       fill="red" cx="50" cy="80" r="10"/>
+      <use href="#piece42" 
+          x="50" y="80"
+        onmousedown="drag_mousedown(event)"
+          />
+      <defs>
+       <circle
+         id="piece42"
+         cx="0" cy="0"
+         fill="red" r="10"/>
+      </defs>
     </svg>
-<script src="script.js"></script>
+    <script src="script.js"></script>
   </body>
 </html>