-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (47 loc) · 1.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const files = ["assets/IMG_7392.jpg", "assets/IMG_7393.jpg", "assets/IMG_7394.jpg", "assets/IMG_7395.jpg"];
const filesLength = files.length
const range = 50
function handleOrientation(e){
const gamma = Math.min(Math.max(e.gamma + range/2, 0), range);
// console.log(gamma);
const index = Math.min(Math.floor(gamma/(range/filesLength)), filesLength-1);
console.log(index);
document.getElementById("img").src = files[index];
}
async function requestDeviceOrientation() {
document.getElementById("information").innerHTML = "requesting";
if(typeof DeviceOrientationEvent != 'undefined' && typeof DeviceOrientationEvent.requestPermission === 'function'){
document.getElementById("information").innerHTML = "requesting, ios ?";
try{
const permissionState = await DeviceOrientationEvent.requestPermission()
document.getElementById("information").innerHTML = "requesting, ios 1 ?";
if(permissionState === 'granted'){
document.getElementById("information").innerHTML = "requesting, ios ok";
window.addEventListener('deviceorientation', handleOrientation)
}
}catch(error){
console.error(error)
document.getElementById("information").innerHTML = "requesting, ios :((";
}
}else if('DeviceOrientationEvent' in window){
window.addEventListener('deviceorientation', handleOrientation)
document.getElementById("information").innerHTML = "requesting, easy";
}else{
alert('not supported')
document.getElementById("information").innerHTML = "not supported";
}
}
let container = document.querySelector(".container");
let icon = document.querySelector("i");
function handleDoubleClick(){
console.log("segesr")
icon.style.transform = "translate(-50%,50%) scale(1)";
icon.style.opacity = 0.8;
icon.style.color = "red";
setTimeout(function () {
icon.style.opacity = 0;
}, 1000);
setTimeout(function () {
icon.style.transform = "translate(-50%,50%) scale(0)";
}, 1000);
}