camera api (含圖片預(yù)覽)
參考地址
主要為利用input type=file, accept="image/*" 進(jìn)行處理
圖片預(yù)覽方式(兩種)
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 電話的接入或者彈出信息等比較高級(jí)的事件觸發(fā),一般做保存操作
- touchmove
- geolocation
參考地址
注意谷歌瀏覽器要https才能提供定位服務(wù)
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 表示方向數(shù)據(jù)由設(shè)備本身坐標(biāo)系提供
this.alpha = doe.alpha // 繞Z軸0-360 進(jìn)入時(shí)手機(jī)水平正對(duì)的方向?yàn)?或360
this.beta = doe.beta // 繞X軸-180~180 描述由前向后旋轉(zhuǎn)
this.gamma = doe.gamma // 繞Y軸-90~90 描述由左向右旋轉(zhuǎn)
}, true)
// chrome v65 只支持accelerationIncludingGravity和interval(應(yīng)該因?yàn)橐恍┫拗茮](méi)有找到),其它瀏覽器最新版基本都支持
window.addEventListener('devicemotion', (dme) => {
this.acceleration = dme.acceleration
this.accelerationIncludingGravity = dme.accelerationIncludingGravity
this.rotationRate = dme.rotationRate
this.interval = dme.interval
}, false)
Pointer Lock(鼠標(biāo)鎖定)
參考地址
<button onclick="lockPointer();">鎖住它!</button>
<div id="pointer-lock-element" style="width:500px;height:500px;background-color: red"></div>
// 簡(jiǎn)單示例,將鼠標(biāo)鎖定在 pointer-lock-element 元素內(nèi)
let = document.getElementById("pointer-lock-element");
document.addEventListener("mousemove", function(e) {
var movementX = e.movementX
movementY = e.movementY
// 打印鼠標(biāo)移動(dòng)的增量值。
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();
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。