1

我已經實現了畫布對象的指針事件。我需要知道我們如何檢測觸摸事件的手指數量。這是我的一段代碼:如何在IE中檢測指針事件的手指計數11

canvasObj.addEventListener('pointerenter', mouseEnterCall, false); 
canvasObj.addEventListener('pointerdown', mouseDownCall, false); 
canvasObj.addEventListener('pointermove', mouseMoveCall, false); 
canvasObj.addEventListener('pointerup', mouseUpCall, false); 
canvasObj.addEventListener('pointerout', mouseOutCall, false); 

感謝您的幫助。

+0

這是一段代碼。 canvasObj.addEventListener('pointerenter',mouseEnterCall,false); canvasObj.addEventListener('pointerdown',mouseDownCall,false); canvasObj.addEventListener('pointermove',mouseMoveCall,false); canvasObj.addEventListener('pointerup',mouseUpCall,false); canvasObj.addEventListener('pointerout',mouseOutCall,false); – Joe

+1

對不起,我感到困惑。我試圖使用上述模型來檢測IE11瀏覽器上的手指數量。有沒有可能或有其他方法? – Joe

+0

我想我在這裏找到答案。 http://stackoverflow.com/questions/15811694/space-between-touch-points-on-ie10 – Joe

回答

2

沒有內置的屬性,可以讓您在屏幕上顯示當前的手指數量(活動指針)。但這裏有一些簡單的代碼,將做到這一點:

var pointerCount = 0; //Stores current number of "active pointers" 
window.addEventListener("pointerdown", addPointer, true); 
window.addEventListener("pointerup", removePointer, true); 
window.addEventListener("pointercancel", removePointer, true); 
function addPointer(e) { pointerCount++ } 
function removePointer(e) { pointerCount-- } 

可以修改addPointer只計算觸摸指針,如果這就是你想要的東西:

function addPointer(e) { if (e.pointerType === "touch") pointerCount++ } 

請注意,您將需要修改這個代碼在某種程度上,如果你還想支持IE10,它有一個標準的早期版本(前綴)。