Skip to content

Instantly share code, notes, and snippets.

@SpaceShot
Forked from anonymous/index.html
Created August 26, 2014 19:48
Show Gist options
  • Save SpaceShot/e418846da3065d77dfa8 to your computer and use it in GitHub Desktop.
Save SpaceShot/e418846da3065d77dfa8 to your computer and use it in GitHub Desktop.
Pointer Events Demonstration
<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