Maxim Mazurok
Maxim Mazurok

Reputation: 4138

How to measure the force of pressure on the Web?

Recently Apple introduced a new trackpad, which supports the "Force Touch" feature. It is similar to Wacom tablets for painting because, with special software, you can measure the force (weight) of pressing.
So, is it possible to get these values using web-technologies like javascript? Do browsers provide any API and information about pressing force?

P.S. I find this question relative to mine one, but it is not about the web: Android, IOS force pressing on the screen

Upvotes: 1

Views: 321

Answers (2)

stuyam
stuyam

Reputation: 10049

For both iOS (iPhone 6s) and Mac (new MabBook Pro with Force Touch) you can use Pressure.js. It is a JavaScript library that allows you to simply use force touch on the web. Here is an example of the basic usage:

Pressure.set('#element', {
  change: function(force, event){
    // this is called every time there is a change in pressure
  },
  unsupported: function(){
    // this is called if device or browser does not support Force or 3D touch
  }
});

Upvotes: 1

Blazemonger
Blazemonger

Reputation: 92943

You're looking for the pressure attribute of a PointerEvent. This isn't widely supported across browsers yet, as it's not a final spec, but as of this writing IE11 has some support.

Upvotes: 1

Related Questions