Navigator.vibrate() - Web APIs 编辑
The 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.
Syntax
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,30,200,30,200,30,200,30,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
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论