Existuje nejaký spôsob, ako zistiť kliknutie Force Click pomocou Javascriptu? Viem, že existujú spôsoby, ako odhaliť pravidelné a pravé kliknutia, ale čo s kliknutiami Force?
odpovede:
2 pre odpoveď č. 1Počúvajte webkitmouseforcewillbegin
a webkitmouseforcedown
diania. Úroveň sily môžete získať z webkitForce
vlastnosť v objekte prešiel do obsluhy udalostí.
Samozrejme, funguje to iba na Safari na Macoch s podporou Force Touch.
zdroj: Dokumentácia programovania WebKit DOM
3 pre odpoveď č. 2
Našiel som knižnicu JS nazvanú Pressure.js čo zjednodušuje ovládanie funkcie Force / 3D Touch. Pracuje pre iOS s 3D dotykom a OSX s dotykom na silu. Ak ju používate iba na silu, dotknite sa Macu, môžete ho použiť takto:
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"});
Na {only: "force"}
možnosti na konci uistite sa, že to funguje len pre force touch, Macu a nie aj na iOS.Ak chcete spustiť na oboch jednoduché odstrániť túto možnosť.