Gamepad.axes 特性为 Gamepad interface returns an array representing the controls with axes present on the device (e.g. analog thumb sticks).-

Each entry in the array is a floating point value in the range -1.0 – 1.0, representing the axis position from the lowest value (-1.0) to the highest value (1.0).

句法

readonly    attribute double[]            axes;
					

范例

function gameLoop() {
  if(navigator.webkitGetGamepads) {
    var gp = navigator.webkitGetGamepads()[0];
  } else {
    var gp = navigator.getGamepads()[0];
  }
  if(gp.axes[0] != 0) {
    b -= gp.axes[0];
  } else if(gp.axes[1] != 0) {
    a += gp.axes[1];
  } else if(gp.axes[2] != 0) {
    b += gp.axes[2];
  } else if(gp.axes[3] != 0) {
    a -= gp.axes[3];
  }
  ball.style.left = a*2 + "px";
  ball.style.top = b*2 + "px";
  var start = rAF(gameLoop);
};
					

An array of double 值。

规范

规范 状态 注释
Gamepad
The definition of 'Gamepad.axes' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
axes Chrome 35
35
不支持 21 — 34 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 29
29
不支持 24 — 28 Disabled
Disabled ). To change preferences in Firefox, visit
IE No Opera 22
22
不支持 15 — 21 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 10.1 WebView Android No Chrome Android 35
35
不支持 25 — 34 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0 Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

Using the Gamepad API

元数据

  • 最后修改:
  1. 手柄 API
  2. Gamepad
  3. 特性
    1. axes
    2. buttons
    3. connected
    4. displayId
    5. hand
    6. hapticActuators
    7. id
    8. index
    9. 映射
    10. pose
    11. timestamp
  4. Related pages for Gamepad API
    1. GamepadButton
    2. GamepadEvent
    3. Navigator.getGamepads()
    4. Window.ongamepadconnected
    5. Window.ongamepaddisconnected

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1