Skip to content
Snippets Groups Projects
index.html 1.27 KiB
Newer Older
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <textarea style="width: 100%; height: 500px" id="textfield"></textarea>
    <script src="js/app.js"></script>

    <svg id="whiteboard" width="100%" height="100%"></svg>
    <script>
      var whiteboard = document.getElementById("whiteboard")

      var painting = false
      var path

      whiteboard.onmousedown = function(e) {
        painting = true

        var mouse = {
          x: e.offsetX,
          y: e.offsetY
        }

        path = document.createElementNS("http://www.w3.org/2000/svg", "path")

        path.setAttribute("d", "M" + mouse.x + " " + mouse.y)
        path.setAttribute("stroke", "blue")
        path.setAttribute("stroke-width", 3)
        path.setAttribute("fill", "none")
        path.setAttribute("pointer-events", "none")

        whiteboard.appendChild(path)
      }

      whiteboard.onmouseup = function(e) {
        painting = false
      }

      whiteboard.onmousemove = function(e) {
        var mouse = {
          x: e.offsetX,
          y: e.offsetY
        }

        if (painting) {
          path.setAttribute(
            "d",
            path.getAttribute("d") + " L" + mouse.x + " " + mouse.y
          )
        }
      }
    </script>
  </body>
</html>