TouchEvent:targetTouches 屬性
targetTouches 只讀屬性是一個 TouchList,它列出了所有仍與觸控表面接觸並且其 touchstart 事件發生在與當前目標元素相同的目標 element 內部的觸控點對應的 Touch 物件。
值
一個 TouchList,列出了所有仍與觸控表面接觸並且其 touchstart 事件發生在與當前目標 element 相同的目標 element 內部的觸控點對應的 Touch 物件。
示例
此示例演示了 TouchEvent 物件的 TouchEvent.targetTouches 屬性。TouchEvent.targetTouches 屬性是一個 TouchList 物件,它包含那些當前正在觸控表面並且從作為當前事件目標的元素上開始的觸控點。因此,targetTouches 列表是 touches 列表的嚴格子集。
在下面的程式碼片段中,該函式比較 touches 列表的長度和 targetTouches 列表的長度,如果長度相同則返回 true,否則返回 false。
js
function touches_in_target(ev) {
// Return true if all of the touches are within the target element;
// otherwise return false.
return ev.touches.length === ev.targetTouches.length;
}
規範
| 規範 |
|---|
| 觸控事件 # dom-touchevent-targettouches |
瀏覽器相容性
載入中…