A Pen by Captain Anonymous on CodePen.
Created
August 26, 2014 19:47
-
-
Save anonymous/09e4265ed4f187bb5a53 to your computer and use it in GitHub Desktop.
A Pen by Anonasaurus Rex.
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
<span id="support">No multi-touch support</span><br> | |
<canvas id="drawSurface" width="500px" height="500px" style="border:1px solid black;"></canvas> |
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
window.addEventListener('load', function() { | |
var canvas = document.getElementById("drawSurface"), | |
context = canvas.getContext("2d"); | |
if (window.navigator.pointerEnabled) { | |
canvas.addEventListener("pointermove", paint, false); | |
if(window.navigator.maxTouchPoints>1) | |
document.querySelector("#support").innerText = "Your hardware supports multi-touch!"; | |
} | |
else { | |
//Provide fallback for user agents that do not support Pointer Events | |
canvas.addEventListener("mousemove", paint, false); | |
} | |
function paint(event) { | |
if(event.buttons>0) | |
context.fillRect(event.clientX, event.clientY, 5, 5); | |
} | |
}); |
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
html { | |
touch-action: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment