blob: a7c83775a8c4e08e4c5ba03d0298a757c597b11f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
---
title: GamepadButton.value
slug: Web/API/GamepadButton/value
translation_of: Web/API/GamepadButton/value
---
<p>{{APIRef("Gamepad API")}}</p>
<p>{{domxref("GamepadButton")}}接口下的 <code><strong>GamepadButton.value</strong></code> 属性返回一个双精浮点值来表示许多现代控制器上的模拟按钮的状态,比如说扳机键。</p>
<p>其值被规范于范围 <code>0.0</code> — <code>1.0</code> 内, <code>0.0</code> 表示按钮没有被按下,<code>1.0</code> 则表示按钮被完全按下。</p>
<h2 id="语法">语法</h2>
<pre class="brush: js"><span class="idlInterface" id="idl-def-GamepadButton"><span class="idlAttribute">var pressState = navigator.getGamepads()[0].value;
// 只读属性、双精浮点值</span></span>
</pre>
<h2 id="示例">示例</h2>
<pre class="brush: js">var gp = navigator.getGamepads()[0];
if(gp.buttons[0].value > 0) {
// 响应模拟按钮被按下
} </pre>
<h2 id="值">值</h2>
<p>一个 {{domxref("double")}} (双精浮点值)。</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
<tr>
<td>{{SpecName("Gamepad", "#widl-GamepadButton-value", "GamepadButton.value")}}</td>
<td>{{Spec2("Gamepad")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.GamepadButton.value")}}</p>
<h2 id="另请参阅">另请参阅</h2>
<p><a href="/en-US/docs/Web/Guide/API/Gamepad">使用 Gamepad API</a></p>
|