The following example is a basic paint application that works with mouse, touch, and pen via pointer events.
<style>
html {
-ms-touch-action: none; /* Shunt all pointer events to JavaScript code. */
}
</style>
<canvas id="drawSurface" width="500px" height="500px" style="border:1px solid black;"></canvas>
<script type='text/javascript'>
window.addEventListener('load', function() {
var canvas = document.getElementById("drawSurface"),
context = canvas.getContext("2d");
if (window.navigator.msPointerEnabled) {
canvas.addEventListener("MSPointerMove", paint, false);
}
else {
canvas.addEventListener("mousemove", paint, false);
}
function paint(event) {
context.fillRect(event.clientX, event.clientY, 5, 5);
}
});
</script>
有关更多详细信息,请查看此链接