MDN self-hosted library · e01.org

Touch: force property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
someElement.addEventListener("touchstart", (e) => {
  // Iterate through the list of touch points and log each touch
  // point's force.
  for (let 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}`);
  }
});