This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
The Touch.force read-only property returns the amount of pressure the user is applying to the touch surface for a Touch point.
Syntax
touchItem.force;
Return value
A float that represents the amount of pressure the user is applying to the touch surface. This is a value between 0.0 (no pressure) and 1.0 (the maximum amount of pressure the hardware can recognize). A value of 0.0 is returned if no value is known (for example the touch device does not support this property). In environments where force is known, the absolute pressure represented by the force attribute, and the sensitivity in levels of pressure, may vary.
Example
This example illustrates using the Touch interface's Touch.force property. This property is a relative value of pressure applied, in the range 0.0 to 1.0, where 0.0 is no pressure, and 1.0 is the highest level of pressure the touch device is capable of sensing.
In following code snippet, the touchstart event handler iterrates through the targetTouches list and logs the force value of each touch point but the code could invoke different processing depending on the value.
someElement.addEventListener('touchstart', function(e) {
// Iterate through the list of touch points and log each touch
// point's force.
for (var i=0; i < e.targetTouches.length; i++) {
// Add code to "switch" based on the force value. For example
// minimum pressure vs. maximum pressure could result in
// different handling of the user's input.
console.log("targetTouches[" + i + "].force = " + e.targetTouches[i].force);
}
}, false);
Specifications
| Specification | Status | Comment |
| Touch Events – Level 2 | Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Chrome
Full support Yes |
Edge
Full support ≤79 |
Firefox
Full support Yes |
IE
No support No |
Opera
Full support Yes |
Safari
No support No |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
Touch.force by Mozilla Contributors is licensed under CC-BY-SA 2.5.