Navigator.vibrate()
method pulses the vibration hardware on the device, if such hardware exists. If the device doesn't support vibration, this method has no effect. If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.
If the method was unable to vibrate because of invalid parameters, it will return
false
, else it returns
true
. If the pattern leads to a too long vibration, it is truncated: the max length depends on the implementation.
var successBool = window.navigator.vibrate(pattern);
pattern
Passing a value of
0
, an empty array, or an array containing all zeros will cancel any currently ongoing vibration pattern.
window.navigator.vibrate(200); // vibrate for 200ms window.navigator.vibrate([100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]); // Vibrate 'SOS' in Morse.
| 规范 | 状态 | 注释 |
|---|---|---|
| 振动 API | 推荐 | Linked to spec is the latest editor's draft; W3C version is a REC. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
vibrate
|
Chrome 32 | Edge ≤79 |
Firefox
16
|
IE No | Opera No | Safari No |
WebView Android
4.4.3
|
Chrome Android
32
|
Firefox Android
16
|
Opera Android
Yes
|
Safari iOS No |
Samsung Internet Android
2.0
|
完整支持
不支持
见实现注意事项。
要求使用供应商前缀或不同名称。
Navigator
activeVRDisplays
appCodeName
appName
appVersion
battery
buildID
clipboard
connection
cookieEnabled
credentials
deviceMemory
doNotTrack
geolocation
keyboard
语言
languages
locks
maxTouchPoints
mediaDevices
mediaSession
onLine
oscpu
permissions
platform
product
productSub
serviceWorker
userAgent
vendor
vendorSub
webdriver
xr