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>
For more details checkout this link
更新:事實證明,如果我在Windows中創建VS2010新的MVC3項目8操作系統,看起來像指針可以被檢測到。但是,如果項目是在Windows 7中創建的,那麼它將無法工作。這太奇怪了...... – DLee