Skip to content
Permalink
Browse files

Tutorial 003: Update example code

* Add onLoadPage() function
  • Loading branch information
chobocho committed Nov 14, 2019
1 parent b2714b2 commit bb093499bd2343fc11495cf6077c92a7d7250772
Showing with 32 additions and 0 deletions.
  1. +1 −0 doc/tutorial/003/src/painter.html
  2. +31 −0 doc/tutorial/003/src/painter.js
@@ -124,5 +124,6 @@
</span>
</div>
</div>
<script src="painter.js"></script>
</body>
</html>
@@ -0,0 +1,31 @@
var cvs;
var canvas;

function mouseListener(event) {
switch (event.type) {
case "mousedown":
console.log("mousedown");
break;
case "mousemove":
console.log("mousemove");
break;
case "mouseup":
console.log("mouseup");
break;
case "mouseout":
console.log("mouseout");
break;
}
}

function onLoadPage() {
canvas = document.getElementById("canvas");
cvs = canvas.getContext("2d");

canvas.addEventListener("mousedown", mouseListener);
canvas.addEventListener("mousemove", mouseListener);
canvas.addEventListener("mouseout", mouseListener);
canvas.addEventListener("mouseup", mouseListener);
}

window.onload = onLoadPage();

0 comments on commit bb09349

Please sign in to comment.
You can’t perform that action at this time.