iPhone 6s 具有用于原生应用程序的 3D 触控 API。我想知道 Apple 是否为 Web 应用程序启用了 Javascript 的 3D 触摸访问?
就像我们使用标准的触摸事件一样
element.addEventListener("touchstart", handleStart, false);
iPhone 6s 具有用于原生应用程序的 3D 触控 API。我想知道 Apple 是否为 Web 应用程序启用了 Javascript 的 3D 触摸访问?
就像我们使用标准的触摸事件一样
element.addEventListener("touchstart", handleStart, false);
Safari 9 在桌面上支持它。请参阅Apple 的 WebKit DOM 编程主题中的Responding to Force Touch Events from JavaScript。
不过,我找不到任何关于在 iOS 上的 Safari 9 中使用它的文档。
您可以在 iPhone 和 Mac 上使用强制触摸。您可以使用 JS 库Pressure.js。如果您有 iPhone 6s 或带有新 Force Touch 触控板的新 Macbook,那么在 iOS 和 OSX 上获取 Force 和 3D Touch 值真的很容易。目前仅支持 Safari,但希望很快会有更多浏览器支持。
语法也很简单,这里有一个例子:
Pressure.set('#element', {
start: function(){
// this is called on force start
},
end: function(){
// this is called on force end
},
startDeepPress: function(){
// 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
// here the 'force' variable passed in container the current pressure force
},
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
}
});