Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2014 19:47
Show Gist options
  • Save anonymous/09e4265ed4f187bb5a53 to your computer and use it in GitHub Desktop.
Save anonymous/09e4265ed4f187bb5a53 to your computer and use it in GitHub Desktop.
A Pen by Anonasaurus Rex.
<span id="support">No multi-touch support</span><br>
<canvas id="drawSurface" width="500px" height="500px" style="border:1px solid black;"></canvas>
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);
}
});
html {
touch-action: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment