Created
May 17, 2011 15:58
-
-
Save thash/976734 to your computer and use it in GitHub Desktop.
plain mouse events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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