Created
May 4, 2011 00:11
-
-
Save cyberfox/954503 to your computer and use it in GitHub Desktop.
A simple <canvas> element test
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Testing HTML5 Canvas element</title> | |
<script src="jquery.min.js" type="text/javascript"></script> | |
</head> | |
<body> | |
This is a test of the HTML5 Canvas element. | |
<canvas id="drawing_canvas" width="800" height="600" style="position: absolute; top: 0; left: 0;"> | |
</canvas> | |
<script type="text/javascript"> | |
canvas = document.getElementById('drawing_canvas'); | |
var ctx = canvas.getContext('2d'); | |
var lastX = null; | |
var lastY = null; | |
$("#drawing_canvas").mousemove(function(event) { | |
if(lastX != null) { | |
ctx.globalCompositeOperation = 'destination-out'; | |
ctx.lineWidth = 2.5; | |
ctx.strokeStyle = 'rgba(0, 0, 0, 1.0)'; | |
ctx.stroke(); | |
} | |
ctx.beginPath(); | |
ctx.moveTo(0, 0); | |
ctx.lineTo(event.pageX, event.pageY); | |
console.log("draws: lineTo(" + event.pageX + ", " + event.pageY + ")"); | |
lastX = event.pageX; | |
lastY = event.pageY; | |
ctx.globalCompositeOperation = 'source-over'; | |
ctx.lineWidth = 1; | |
ctx.strokeStyle = 'rgba(200, 0, 0, 1.0)'; | |
ctx.stroke(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment