2015-11-03 37 views

回答

2

收聽webkitmouseforcewillbeginwebkitmouseforcedown事件。您可以從傳入事件處理程序的對象中的webkitForce屬性中獲取強制級別。

當然,這隻適用於具有Force Touch支持的Mac上的Safari。

來源:WebKit DOM Programming Documentation

3

我發現一個JS庫調用Pressure.js,使操作力/ 3D觸控簡單。它適用於iOS和3D touch以及強制觸摸的OSX。如果你正在使用它的正義的力量在Mac上的觸摸,你可以使用這樣的:

Pressure.set('#element', { 
    start: function(event){ 
    // this is called on force start 
    }, 
    end: function(){ 
    // this is called on force end 
    }, 
    startDeepPress: function(event){ 
    // this is called on "force click"/"deep press", aka once the force is greater than 0.5 
    }, 
    endDeepPress: function(){ 
    // this is called when the "force click"/"deep press" end 
    }, 
    change: function(force, event){ 
    // this is called every time there is a change in pressure 
    }, 
    unsupported: function(){ 
    // this is called once there is a touch on the element and the device or browser does not support Force or 3D touch 
    } 
}, {only: 'force'}); 

末的{only: 'force'}選項確保它只能運行在Mac力觸和不也是在iOS上。如果你希望它運行在兩個簡單的刪除該選項。

相關問題