HTML5 device access 机器设备浏览详解

日期:2020-09-18 类型:科技新闻 

关键词:html网页制作,php网页制作,网页设计稿,网页编辑工具,学生网页设计模板

camera api (含照片预览)

参照详细地址

关键为运用input type=file, accept="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 (触摸屏恶性事件)

参照详细地址

  1. touchstart
  2. touchen
  3. touchcancel 电話的接入或弹出信息内容等较为高級的恶性事件开启,1般做储存实际操作
  4. touchmove
  5. geolocation

参照详细地址

留意谷歌访问器要https才可以出示精准定位服务

    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition((position) => {
            this.geolocation = `latitude:${position.coords.latitude},longitude:${position.coords.longitude}`
        }, (err) => {
            console.log(err);
        }, {
                enableHighAccuracy: 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⑶60 进到时手机上水平正对的方位为0或360
        this.beta = doe.beta // 绕X轴⑴80~180 叙述由前向后转动
        this.gamma = doe.gamma // 绕Y轴⑼0~90 叙述由左向右转动
    }, true)

    // chrome v65 只适用accelerationIncludingGravity和interval(应当由于1些限定沒有寻找),其它访问器全新版基础都适用
    window.addEventListener('devicemotion', (dme) => {
        this.acceleration = dme.acceleration
        this.accelerationIncludingGravity = dme.accelerationIncludingGravity
        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();
    }

以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。