From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/web/api/navigator/getgamepads/index.html | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 files/zh-cn/web/api/navigator/getgamepads/index.html (limited to 'files/zh-cn/web/api/navigator/getgamepads') diff --git a/files/zh-cn/web/api/navigator/getgamepads/index.html b/files/zh-cn/web/api/navigator/getgamepads/index.html new file mode 100644 index 0000000000..454b4f4329 --- /dev/null +++ b/files/zh-cn/web/api/navigator/getgamepads/index.html @@ -0,0 +1,107 @@ +--- +title: Navigator.getGamepads() +slug: Web/API/Navigator/getGamepads +translation_of: Web/API/Navigator/getGamepads +--- +

{{APIRef("Gamepad API")}}{{SeeCompatTable}}

+ +

调用 Navigator.getGamepads() 方法会返回一个数组:第一个值为 null ,其他的值均为 {{ domxref("Gamepad") }} 对象,表示每一个与设备连接的游戏手柄。所以如果没有连接任何游戏手柄,这个方法将只会返回 null

+ +

语法

+ +
 var arrayGP = navigator.getGamepads();
+ +

样例

+ +
window.addEventListener("gamepadconnected", function(e) {
+  var gp = navigator.getGamepads()[e.gamepad.index];
+  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
+  gp.index, gp.id,
+  gp.buttons.length, gp.axes.length);
+});
+ +

标准

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Gamepad', '', 'The Gamepad API specification')}}{{Spec2('Gamepad')}}初始定义
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
General support +

21.0 {{ property_prefix("webkit") }}
+ 35.0

+
{{CompatVersionUnknown}}{{ CompatGeckoDesktop("29.0") }} [1]{{ CompatNo() }} +

15.0 {{ property_prefix("webkit") }}
+ 22.0

+
{{ CompatNo() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
General support{{ CompatNo() }}{{CompatVersionUnknown}}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
+
+ +

[1] 自 Firefox 24 起可以通过偏好设置启用。

+ +

另请参阅

+ + -- cgit v1.2.3-54-g00ecf