HTML5 device access 设备访问详解
建站知识 2021-07-02 23:00www.168986.cn长沙网站建设
camera api (含图片预览)
主要为利用input type=file, aept="image/" 进行处理
图片预览方式(两种)
const file = e.target.files[0] // 方式1 const url1 = window.URL.createObjectURL(file); let url2 // 方式2 const reader = new FileReader(); reader.onload = (e) => { url2 = e.target.result; }; reader.readAsDataURL(file);
touch events (触屏事件)
- touchstart
- touchen
- touchcancel 电话的接入或者弹出信息等比较高级的事件触发,一般做保存操作
- touchmove
- geolocation
注意谷歌浏览器要https才能提供定位服务
if (navigator.geolocation){ navigator.geolocation.getCurrentPosition((position) => { this.geolocation = `latitude:${position.coords.latitude},longitude:${position.coords.longitude}` }, (err) => { console.log(err); }, { enableHighAuracy: true, maximumAge : 30000, // buffer memory timre timeout : 27000 // waiting time }) } else { alert('geolocation not supported!') }
device orientation and motion
window.addEventListener('deviceorientation',(doe) => { this.absolute = doe.absolute //false 表示方向数据由设备本身坐标系提供 this.alpha = doe.alpha // 绕Z轴0-360 进入时手机水平正对的方向为0或360 this.beta = doe.beta // 绕X轴-180~180 描述由前向后旋转 this.gamma = doe.gamma // 绕Y轴-90~90 描述由左向右旋转 }, true) // chrome v65 只支持aelerationIncludingGravity和interval(应该因为一些限制没有找到),其它浏览器最新版基本都支持 window.addEventListener('devicemotion', (dme) => { this.aeleration = dme.aeleration this.aelerationIncludingGravity = dme.aelerationIncludingGravity this.rotationRate = dme.rotationRate this.interval = dme.interval }, false)
Pointer Lock(鼠标锁定)
<button onclick="lockPointer();">锁住它!</button> <div id="pointer-lock-element" style="width:500px;height:500px;background-color: red"></div>
// 简单示例,将鼠标锁定在 pointer-lock-element 元素内 let = document.getElementById("pointer-lock-element"); document.addEventListener("mousemove", function(e) { var movementX = e.movementX movementY = e.movementY // 打印鼠标移动的增量值。 console.log("X=" + movementX, "Y=" + movementY); }, false); function lockPointer() { elem = document.getElementById("pointer-lock-element"); elem.requestPointerLock = elem.requestPointerLock || elem.mozRequestPointerLock || elem.webkitRequestPointerLock; elem.requestPointerLock(); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
长沙网站设计
- 如何进行东阳SEO关键词优化?
- 边坝哪有关键词排名优化:提升你的网站流量与
- 安国百度优化服务:提升您的在线可见性
- 阜康新手做SEO怎么做
- 山西seo网站排名关键词优化:提升您网站曝光率
- 临沂seo网站排名关键词优化:提高你的网站可见
- 广西SEO网站推广怎样付费比较合理
- 双辽SEO网站推广:提升你的网站可见性与流量
- 辽宁企业网站优化购买方式有哪些
- 提升宝清百度SEO排名的实用技巧与策略
- 静宁百度SEO排名:提升您网站曝光率的关键策略
- 彭州百度SEO排名的提升策略和实施指南
- 广南百度关键词SEO:提升网站排名的关键策略
- 辽宁关键词优化怎么做论坛营销
- 吉林百度seo排名如何做到让用户满意
- 内黄百度优化服务:提升在线可见性的关键