Skip to content

Instantly share code, notes, and snippets.

@thash
Created May 17, 2011 15:58
Show Gist options
  • Save thash/976734 to your computer and use it in GitHub Desktop.
Save thash/976734 to your computer and use it in GitHub Desktop.
plain mouse events
var down = false;
canvas.addEventListener('mousedown', function (e) {
down = true;
ctx.beginPath();
ctx.moveTo(e.clientX, e.clientY);
}, false);
window.addEventListener('mousemove', function (e) {
if (!down) return;
console.log(e.clientX, e.clientY);
ctx.lineTo(e.clientX, e.clientY);
ctx.stroke();
}, false);
window.addEventListener('mouseup', function (e) {
if (!down) return;
ctx.lineTo(e.clientX, e.clientY);
ctx.stroke();
ctx.closePath();
down = false;
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment