这篇翻译不完整。请帮忙从英语翻译这篇文章

Navigator.vibrate() 方法使设备(有振动硬件)产生有频率的振动。若设备不支持振动,该方法将无效。若某振动方式已经在进行中(当该方法调用时),则前一个振动方式停止,新的取而代之。

该方法若因为提供无效的参数使得无法使设备振动,它将返回false,否则返回true。若振动方案导致长时间的振动,它会被截断:最大长度取决于每个实现。

语法

var successBool = window.navigator.vibrate(pattern);
pattern
Provides a pattern of vibration and pause intervals. Each value indicates a number of milliseconds to vibrate or pause, in alternation. You may provide either a single value (to vibrate once for that many milliseconds) or an array of values to alternately vibrate, pause, then vibrate again. See Vibration API for details.

Passing a value of 0, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.

Examples

window.navigator.vibrate(200); // vibrate for 200ms
window.navigator.vibrate([100,30,100,30,100,200,200,30,200,30,200,200,100,30,100,30,100]); // Vibrate 'SOS' in Morse.

Specifications

Specification Status Comment
Vibration API Recommendation Linked to spec is the latest editor's draft; W3C version is a REC.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 未实现 11.0 (11.0) moz
16.0 (16.0) (no prefix) [1]
未实现 未实现 未实现
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) webkit
(Yes) (unprefixed) [2][3]
(Yes) webkit
(Yes) (unprefixed) [2][3]
11.0 (11.0) moz
16.0 (16.0) (no prefix) [1]
未实现 (Yes)[3] 未实现

[1] When the vibration pattern is too long or any of its elements are too large, until Firefox 26 included, Gecko threw an exception, instead of returning false (bug 884935). From Firefox 32 onwards, it returns true but truncates the pattern (bug 1014581).

[2] Beginning in Chrome 55, this is not supported in cross-origin iframes.

[3] Beginning in Chrome 60/Opera 47, this method requires a user gesture. Otherwise it returns false.

See also

文档标签和贡献者

标签: 
 此页面的贡献者: nDos
 最后编辑者: nDos,