ios 震动api

Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in a pattern for a given duration.

浏览器供应商提供给我们的许多新API都比台式机用户更面向移动用户。 这些简单的API之一就是Vibration API 。 振动API允许开发人员使用JavaScript引导设备在给定的时间内以某种模式振动。

View Demo观看演示

检测振动API支持 (Detecting Vibration API Support)

It's always good to check for the presence of API support before using it;  here's how you can detect the Vibration API's presence:

使用API​​之前最好先检查一下是否存在API支持。 这是检测振动API是否存在的方法:


// Standards ftw!
var supportsVibrate = "vibrate" in navigator;

The Vibration API consists of only one method provided to the window.navigator object:  vibrate.

Vibration API仅包含提供给window.navigator对象的一种方法: vibrate

振动API基础 (Vibration API Basics)

The navigator.vibrate function accepts either a single number or an array of numbers for a series of vibrations. When using the array method, the even indices represent vibration duration, the odd indices represent a delay before the next vibration.

navigator.vibrate函数接受一系列振动的单个数字或数字数组。 当使用阵列方法时,偶数索引表示振动持续时间,奇数索引表示下一次振动之前的延迟。


// Vibrate once for one second
navigator.vibrate(1000);
// Vibrate multiple times for multiple durations
// Vibrate for three seconds, wait two seconds, then vibrate for one second
navigator.vibrate([3000, 2000, 1000]);

To stop vibration when active, simply pass a 0 or an empty array to the navigator.vibrate method:

要在激活时停止振动,只需将0或空数组传递给navigator.vibrate方法:


// Either of these stop vibration
navigator.vibrate(0);
navigator.vibrate([]);

Realize that vibrations do not loop until stopped with 0 or an empty array;  the single number vibration occurs once and then becomes silent, the array of vibration durations run and becomes silent again.

意识到直到用0或空数组停止振动循环。 单个数振动发生一次然后变为静音,振动持续时间阵列运行并再次变为静音。

持续振动 (Continued Vibration)

Some basic setInterval and clearInterval action will allow us you to create persistent vibration:

一些基本的setIntervalclearInterval动作将使您创建持久的振动:


var vibrateInterval;
// Starts vibration at passed in level
function startVibrate(duration) {
navigator.vibrate(duration);
}
// Stops vibration
function stopVibrate() {
// Clear interval and stop persistent vibrating
if(vibrateInterval) clearInterval(vibrateInterval);
navigator.vibrate(0);
}
// Start persistent vibration at given duration and interval
// Assumes a number value is given
function startPeristentVibrate(duration, interval) {
vibrateInterval = setInterval(function() {
startVibrate(duration);
}, interval);
}

Of course the snippet above doesn't take into account the array method of vibration;  persistent array-based vibration will require calculating the sum of the array items and creating an interval based on that number (with an additional delay, probably).

当然,上面的代码片段并未考虑振动的阵列方法; 基于数组的持久振动将需要计算数组项的总和,并基于该数量创建一个间隔(可能会有额外的延迟)。

View Demo观看演示

为什么要使用振动API? (Why Use the Vibration API?)

This API is clearly targeted toward mobile devices.  The Vibration API would be good for alerts within mobile web applications, and would be especially awesome when used in games or media-heavy applications.  Imagine watching a video on your mobile device, and during an explosion scene, your phone got a bit of a shake.  Or playing Bomberman and feeling a gentle kick when a block explodes!

该API显然是针对移动设备的。 振动API非常适合在移动Web应用程序中发出警报,并且在用于游戏或大量媒体应用程序中时特别棒。 想象一下在移动设备上观看视频,在爆炸场景中,您的手机有些震动。 或扮演Bomberman并在方块爆炸时感到柔和的踢脚!

What do you think of the Vibration API:  immediately useful or not quite yet?

您如何看待Vibration API:立即有用还是不太有用?

At the time of writing, Firefox BETA for Android is the only browser which supports the Vibration API. WebKit landed the Vibration API a while back, but in my testing of iOS Chrome and Safari, as well as Android Chrome and standard browser, I could not find a working vibration property. Opera doesn't appear to support vibration yet either.

在撰写本文时,适用于Android的Firefox BETA是唯一支持Vibration API的浏览器。 WebKit不久前投放了Vibration API ,但在我对iOS Chrome和Safari以及Android Chrome和标准浏览器的测试中,我找不到有效的振动属性。 Opera似乎也不支持振动。

翻译自: https://davidwalsh.name/vibration-api

ios 震动api


http://www.taodudu.cc/news/show-4874470.html

相关文章:

  • 根据银行的标志 获取颜色
  • 网吧会员计费管理系统-javaweb
  • SpringBoot+Vue实现前后端分离的网吧管理系统
  • 万象管理系统需要服务器吗,万象网吧管理系统在使用中常见的几个问题
  • 基于c#的c/s网吧管理系统开发
  • 基于SpringBoot前后端分离的网吧管理系统
  • 基于php网吧会员管理系统-计算机毕业设计
  • SQLserver网吧管理系统数据库
  • 通用网吧管理系统源码 C/S架构
  • 基于php的网吧管理系统,基于ssh/bs/java/asp.net/php/web/安卓的网吧会员消费管理系统...
  • springboot Vue网吧会员信息管理系统java源码介绍
  • python+django网吧会员管理系统
  • smallpdf突然特别慢,找到另外一个也蛮好用
  • 在线PDF转换器
  • 攻防世界 Misc高手进阶区 3分题 小小的PDF
  • pdf转换为word比较少出现乱码的网站
  • SmallPdf如何免费做到无限次转换
  • 在线PPT、EXCEL、JPG、WORD与PDF互转——Smallpdf
  • Smallpdf 轻松玩转PDF。我们爱它。
  • 手机pdf文件转语音_用smallpdf如何将pdf文件转word文档
  • matlab 函数pdf怎么用_smallpdf怎么用转换器合并pdf?
  • matlab 函数pdf怎么用_用smallpdf可以将图片转换成pdf呢?怎么转?
  • 《Smallpdf》简单好用的线上PDF工具
  • matlab 函数pdf怎么用_用smallpdf可以将图片转换成pdf呢?怎么转?-使用教程-Smallpdf转换器_PDF转换器...
  • 比Smallpdf好用的在线转换工具有没有呢?
  • 032_smallpdf
  • Small PDF
  • 谷歌浏览器插件Smallpdf和Markdown Preview Plus的用法
  • 阿里云物联网平台产品架构与优势
  • 【物联网】阿里云物联网应用托管

ios 震动api_震动API相关推荐

  1. jquery 字符串查找_Python Appium 库IOS特有元素查找API介绍

    IOS自动化测试系列文章: 一文带你趟过mac搭建appium测试环境的遇到的坑 appium 实现简易IOS  app自动化测试demo 今天分享的是python appium库中IOS元素查找特定 ...

  2. IOS开发百度地图API入门到精通-用点生成路线,导航,气泡响应

    (转)IOS开发百度地图API入门到精通-用点生成路线,导航,气泡响应 IOS百度地图API开发自定义气泡,点击气泡自动生成路线,以及拖拽 IOS百度地图开发POISearch搜索附近停车场,附近加油 ...

  3. android 触摸时震动,android触屏震动以及震动强度批改

    android触屏震动以及震动强度修改 PhoneWindowManager.java: 在interceptKeyBeforeQueueing函数中 performHapticFeedbackLw( ...

  4. iOS学习—添加震动效果

    一.系统提供的几种震动方法: 导入:#import <AudioToolbox/AudioToolbox.h> 在需要出发震动的地方写上代码: AudioServicesPlaySyste ...

  5. ios 播放声音 播放震动

    在ios开发中,有时候我们需要频繁播放某种提示声音,比如微博刷新提示音.QQ消息提示音等,对于这些短小且需要频繁播放的音频,最好将其加入到系统声音(system sound)里. 注意: ♡♥ 需要播 ...

  6. ios 播放声音和震动

    使用AudioServicesPlaySystemSound 这个接口来进行声音和震动的播放, 当然需要在工程中加入AudioToolBox.framework 1. 播放震动 AudioServic ...

  7. iOS 调用设备震动

    勇~敢~的小伙伴们,大家好,国庆回来,我这个人仿佛一直没有从度假模式中抽离出来,今天看我朋友的博客,看到一篇博客以前从未了解,copy到自己博客里分享给大家~ 原文地址:http://blog.csd ...

  8. iOS开发手机震动效果

    首先要导入 #import <AudioToolbox/AudioToolbox.h> 一行代码搞定: AudioServicesPlaySystemSound(kSystemSoundI ...

  9. 个推 php ios,消息推送API

    消息推送API 简述 个推为开发者提供了如下3种消息推送方式: toSingle :简称"单推",指向单个用户推送消息 toList:简称"批量推",指向制定的 ...

最新文章

  1. 扩增子图片解读7三元图:美的不要不要的,再多用也不过分
  2. log4j:WARN No such property [datePattern] in org.apache.log4j.RollingFileAppender.
  3. Linux 模拟网络丢包和延迟命令
  4. java web删除文件_Web开发为了java端程序能删除文件的解决办法
  5. flume连接kafka_日志收集系统架构设计:(flume+zookeeper+kafka+php+mysql )
  6. 【操作系统】实验 设计一个按优先权调度算法实现处理器调度的程序
  7. ThinkPHP6项目基操(20.实战部分 数据库操作返回值总结)
  8. 区块链100讲:Vitalik Buterin-以太坊Casper惩罚条件的最小化
  9. PSP,CPS1街机模拟器终于出来了(CAPCOM CPS1 Emulators for the PSP),完美!
  10. CentOS安装虚拟打印机
  11. 苹果wifi网速慢怎么办_技巧|iPhone 连接 Wi-Fi 网速慢解决方法
  12. linux alsa 音量参数
  13. 我的世界服务器怎么弄无限矿物,我的世界暮色森林矿石树资源无限刷攻略
  14. 【机器学习百科全书目录】PRML ESL MLAPP 西瓜书 花书 RLAI 统计学习方法 蒲公英书
  15. 使用计算机录制声音10,Win10怎么录制电脑内部声音 Win10电脑自身录音教程
  16. 皮卡车行业调研报告 - 市场现状分析与发展前景预测
  17. fcm基本原理_光谱FCM工作原理
  18. 从SQL出发,程序开发的必备大法
  19. Android-menu键选项菜单的实现
  20. CF891E Lust(推式子,EGF)

热门文章

  1. word2010设置多级别标题
  2. C盘爆满怎么办?C盘没有空间了怎么办?九种方法释放C盘空间
  3. 安卓解决输入的时候 背景下滑问题
  4. 高速缓存存储器——cache
  5. ipad 设备越狱和反越狱
  6. 学习SVM(四) 理解SVM中的支持向量(Support Vector)
  7. matlab的超松弛迭代法,基于MATLAB的超松弛迭代法的电位研究
  8. winXP procession秘钥
  9. 引用 软件开发公司管理手册
  10. JS冒泡排序的6种写法(武当雄风)