簡體   English   中英

使用Javascript for Web App的iOS 3D Touch API

[英]iOS 3D Touch API using Javascript for Web App

iPhone 6s具有用於本機應用程序的3D touch API。 我想知道蘋果是否為網絡應用程序啟用了從Javascript進行3D觸摸訪問?

就像我們使用標准的觸摸事件一樣

element.addEventListener("touchstart", handleStart, false);

Safari 9在桌面上支持它。 請參閱Apple的WebKit DOM編程主題中的“ 響應來自JavaScript的強制觸摸事件”

不過,我在iOS的Safari 9中找不到有關使用它的任何文檔。

您可以在iPhone和Mac上都使用強制觸摸。 您可以使用JS庫Pressure.js 如果您擁有配備了新的Force Touch觸控板的iPhone 6s或新的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
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM