web api instance property
Touch: touchType property
The touchType read-only property of the Touch interface returns the type of device that triggered the touch, such as a stylus, or direct touch from a finger.
Value
A string from the TouchType enumeration. Possible values are:
"direct"- : The touch was made by a direct contact, such as a finger on the screen.
"stylus"- : The touch was made using a stylus or pen device.
Example
Basic usage
someElement.addEventListener(
"touchstart",
(event) => {
for (const touch of event.changedTouches) {
console.log(`Touch type: ${touch.touchType}`);
if (touch.touchType === "stylus") {
// Handle stylus-specific input, such as altitude and azimuth angles.
console.log(`altitudeAngle: ${touch.altitudeAngle}`);
console.log(`azimuthAngle: ${touch.azimuthAngle}`);
}
}
},
false,
);
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.